|
1 | 1 | import { cloneDeep, first as _first, map as _map, groupBy } from 'lodash'; |
2 | 2 | import { Observable, lastValueFrom, from, isObservable, of } from 'rxjs'; |
3 | 3 | import { catchError, mergeMap, map } from 'rxjs/operators'; |
4 | | -import { intervalMap } from './IntervalMap'; |
5 | 4 |
|
6 | 5 | import { |
7 | 6 | AbstractQuery, |
@@ -32,7 +31,7 @@ import { |
32 | 31 | SupplementaryQueryType, |
33 | 32 | TimeRange, |
34 | 33 | } 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'; |
36 | 35 | import { DataSourceWithBackend, getTemplateSrv, TemplateSrv } from '@grafana/runtime'; |
37 | 36 | import { LogRowContextOptions, LogRowContextQueryDirection, QuickwitOptions } from 'quickwit'; |
38 | 37 | import { ElasticQueryBuilder } from 'QueryBuilder'; |
@@ -65,7 +64,6 @@ export class QuickwitDataSource |
65 | 64 | queryBuilder: ElasticQueryBuilder; |
66 | 65 | dataLinks: DataLinkConfig[]; |
67 | 66 | languageProvider: ElasticsearchLanguageProvider; |
68 | | - intervalPattern?: Interval; |
69 | 67 |
|
70 | 68 | constructor( |
71 | 69 | instanceSettings: DataSourceInstanceSettings<QuickwitOptions>, |
@@ -457,7 +455,7 @@ export class QuickwitDataSource |
457 | 455 | query: '', |
458 | 456 | }; |
459 | 457 |
|
460 | | - const timeRange = createContextTimeRange(row.timeEpochMs, direction, this.intervalPattern); |
| 458 | + const timeRange = createContextTimeRange(row.timeEpochMs, direction); |
461 | 459 | const range = { |
462 | 460 | from: timeRange.from, |
463 | 461 | to: timeRange.to, |
@@ -820,35 +818,19 @@ function luceneEscape(value: string) { |
820 | 818 | return value.replace(/([\!\*\+\-\=<>\s\&\|\(\)\[\]\{\}\^\~\?\:\\/"])/g, '\\$1'); |
821 | 819 | } |
822 | 820 |
|
823 | | -function createContextTimeRange(rowTimeEpochMs: number, direction: string, intervalPattern: Interval | undefined) { |
| 821 | +function createContextTimeRange(rowTimeEpochMs: number, direction: string) { |
824 | 822 | const offset = 7; |
825 | 823 | // 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 | + }; |
840 | 829 | } 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 | + }; |
852 | 834 | } |
853 | 835 | } |
854 | 836 |
|
0 commit comments