Skip to content

Commit

Permalink
filter incomplete Queries
Browse files Browse the repository at this point in the history
  • Loading branch information
MGJamJam committed Jul 4, 2024
1 parent f9f8416 commit 698ba2d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
QueryResultMetaNotice,
} from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { filter } from 'lodash';
import {filter, isEmpty} from 'lodash';
import { catchError, lastValueFrom, map, Observable, of } from 'rxjs';

import {
Expand Down Expand Up @@ -87,7 +87,10 @@ export class DataSource extends DataSourceApi<
//filter disabled queries
const enabledQueries = (options.targets = filter(options.targets, (t) => !t.hide));

const promises = enabledQueries.map(async (target) => {
//filter invalid queries
const validQueries = filter(enabledQueries, (t) => this.isQueryComplete(t))

const promises = validQueries.map(async (target) => {
const interval =
target.resultFormat === 'time_series' && target.interval
? calculateQueryInterval(target.interval, from.getTime(), to.getTime())
Expand Down Expand Up @@ -191,6 +194,21 @@ export class DataSource extends DataSourceApi<
}
}

/** check if needed fields are set to avoid sending queries to API that will certainly return an error*/
isQueryComplete(query: BitmovinAnalyticsDataQuery) {
if (isEmpty(query.license) || isEmpty(query.dimension)) {
return false
}

if (query.dimension != null) {
if (!isMetric(query.dimension) && isEmpty(query.metric)) {
return false
}
}

return true
}

getRequestUrl(metric?: Metric, aggregation?: AggregationMethod): string {
let url = '/analytics';
if (this.isAdAnalytics === true) {
Expand Down

0 comments on commit 698ba2d

Please sign in to comment.