Skip to content

Commit d9853f4

Browse files
committed
Issue #12: code review, no need for interval pattern which is only elasticsearch related
1 parent 601a2af commit d9853f4

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

src/datasource.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { cloneDeep, first as _first, map as _map, groupBy } from 'lodash';
22
import { Observable, lastValueFrom, from, isObservable, of } from 'rxjs';
33
import { catchError, mergeMap, map } from 'rxjs/operators';
4-
import { intervalMap } from './IntervalMap';
54

65
import {
76
AbstractQuery,
@@ -32,7 +31,7 @@ import {
3231
SupplementaryQueryType,
3332
TimeRange,
3433
} from '@grafana/data';
35-
import { BucketAggregation, DataLinkConfig, ElasticsearchQuery, Field, FieldMapping, IndexMetadata, Logs, TermsQuery, Interval } from './types';
34+
import { BucketAggregation, DataLinkConfig, ElasticsearchQuery, Field, FieldMapping, IndexMetadata, Logs, TermsQuery } from './types';
3635
import { DataSourceWithBackend, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
3736
import { LogRowContextOptions, LogRowContextQueryDirection, QuickwitOptions } from 'quickwit';
3837
import { ElasticQueryBuilder } from 'QueryBuilder';
@@ -65,7 +64,6 @@ export class QuickwitDataSource
6564
queryBuilder: ElasticQueryBuilder;
6665
dataLinks: DataLinkConfig[];
6766
languageProvider: ElasticsearchLanguageProvider;
68-
intervalPattern?: Interval;
6967

7068
constructor(
7169
instanceSettings: DataSourceInstanceSettings<QuickwitOptions>,
@@ -457,7 +455,7 @@ export class QuickwitDataSource
457455
query: '',
458456
};
459457

460-
const timeRange = createContextTimeRange(row.timeEpochMs, direction, this.intervalPattern);
458+
const timeRange = createContextTimeRange(row.timeEpochMs, direction);
461459
const range = {
462460
from: timeRange.from,
463461
to: timeRange.to,
@@ -820,35 +818,19 @@ function luceneEscape(value: string) {
820818
return value.replace(/([\!\*\+\-\=<>\s\&\|\(\)\[\]\{\}\^\~\?\:\\/"])/g, '\\$1');
821819
}
822820

823-
function createContextTimeRange(rowTimeEpochMs: number, direction: string, intervalPattern: Interval | undefined) {
821+
function createContextTimeRange(rowTimeEpochMs: number, direction: string) {
824822
const offset = 7;
825823
// For log context, we want to request data from 7 subsequent/previous indices
826-
if (intervalPattern) {
827-
const intervalInfo = intervalMap[intervalPattern];
828-
if (direction === LogRowContextQueryDirection.Forward) {
829-
return {
830-
from: dateTime(rowTimeEpochMs).utc(),
831-
to: dateTime(rowTimeEpochMs).add(offset, intervalInfo.amount).utc().startOf(intervalInfo.startOf),
832-
};
833-
} else {
834-
return {
835-
from: dateTime(rowTimeEpochMs).subtract(offset, intervalInfo.amount).utc().startOf(intervalInfo.startOf),
836-
to: dateTime(rowTimeEpochMs).utc(),
837-
};
838-
}
839-
// If we don't have an interval pattern, we can't do this, so we just request data from 7h before/after
824+
if (direction === LogRowContextQueryDirection.Forward) {
825+
return {
826+
from: dateTime(rowTimeEpochMs).utc(),
827+
to: dateTime(rowTimeEpochMs).add(offset, 'hours').utc(),
828+
};
840829
} else {
841-
if (direction === LogRowContextQueryDirection.Forward) {
842-
return {
843-
from: dateTime(rowTimeEpochMs).utc(),
844-
to: dateTime(rowTimeEpochMs).add(offset, 'hours').utc(),
845-
};
846-
} else {
847-
return {
848-
from: dateTime(rowTimeEpochMs).subtract(offset, 'hours').utc(),
849-
to: dateTime(rowTimeEpochMs).utc(),
850-
};
851-
}
830+
return {
831+
from: dateTime(rowTimeEpochMs).subtract(offset, 'hours').utc(),
832+
to: dateTime(rowTimeEpochMs).utc(),
833+
};
852834
}
853835
}
854836

0 commit comments

Comments
 (0)