The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/elasticsearch/index_pattern.ts

44 lines
1.1 KiB

import { toUtc, dateTime } from '@grafana/data';
const intervalMap: any = {
Hourly: { startOf: 'hour', amount: 'hours' },
Daily: { startOf: 'day', amount: 'days' },
Weekly: { startOf: 'isoWeek', amount: 'weeks' },
Monthly: { startOf: 'month', amount: 'months' },
Yearly: { startOf: 'year', amount: 'years' },
};
export class IndexPattern {
constructor(private pattern: any, private interval?: string) {}
getIndexForToday() {
if (this.interval) {
return toUtc().format(this.pattern);
} else {
return this.pattern;
}
}
getIndexList(from: any, to: any) {
if (!this.interval) {
return this.pattern;
}
const intervalInfo = intervalMap[this.interval];
const start = dateTime(from)
.utc()
.startOf(intervalInfo.startOf);
const endEpoch = dateTime(to)
.utc()
.startOf(intervalInfo.startOf)
.valueOf();
const indexList = [];
while (start.valueOf() <= endEpoch) {
indexList.push(start.format(this.pattern));
start.add(1, intervalInfo.amount);
}
return indexList;
}
}