Skip to content

Commit

Permalink
merge main into feat/AN-4120_playwright-e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MGJamJam committed Jul 25, 2024
2 parents f95514e + b6a1fa2 commit 17a5001
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:

- name: Check types
run: yarn run typecheck
- name: Check formatting
run: yarn run format:check
- name: Lint
run: yarn run lint
- name: Unit tests
Expand Down
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore artifacts
dist

# Ignore files created by `@grafana/create-plugin`
.config
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## Development

### Fix

- different query start times with multiple queries due to mutating of grafana start time

### Added

- Default Percentile Value when percentile metric is selected

## 1.1.1

### Added
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add the plugin and acquire your Bitmovin Analytics API key from the [bitmovin da
Configure the datasource:

| Setting | Value |
|--------------|----------------------------------------------------------|
| ------------ | -------------------------------------------------------- |
| URL | `https://api.bitmovin.com/v1` |
| API Key | Your API key |
| Ad Analytics | If checked, the datasource is switched to query ads data |
Expand All @@ -27,18 +27,18 @@ See the [example_dashboard.json](example_dashboard.json) for a demo. Configure t
Add a new panel and select the bitmovin analytics datasource.
Configure the metric with following settings:

| Setting | Description |
|------------------------|------------------------------------------------------------------------------------------|
| License* | Your analytics license |
| Metric* | Aggregation method to use, e.g. `count`, `sum` |
| Dimension* | Dimension to aggregate over |
| Filter | Apply filters to the query |
| Format as time series* | Check the switch to see time series data |
| Group By | Group query by dimension and plot as individual time series |
| Order By | Order query ascending or descending by dimension |
| Limit | Limit the result to given number |
| Interval* | Time granularity of queries, select `AUTO` to automatically adapt to selected time range |
| Alias By | Set the name of series (only visible with multiple queries in one Graph) |
| Setting | Description |
| ----------------------- | ---------------------------------------------------------------------------------------- |
| License\* | Your analytics license |
| Metric\* | Aggregation method to use, e.g. `count`, `sum` |
| Dimension\* | Dimension to aggregate over |
| Filter | Apply filters to the query |
| Format as time series\* | Check the switch to see time series data |
| Group By | Group query by dimension and plot as individual time series |
| Order By | Order query ascending or descending by dimension |
| Limit | Limit the result to given number |
| Interval\* | Time granularity of queries, select `AUTO` to automatically adapt to selected time range |
| Alias By | Set the name of series (only visible with multiple queries in one Graph) |

Settings marked with `*` are required for the time series graph.

Expand All @@ -52,7 +52,7 @@ Configure the metric as described in [Time Series Graph](#time-series-graph) but

## Gauges

Configure the Gauge's `Value Options`, depending on your query.
Configure the Gauge's `Value Options`, depending on your query.

- For table data (`Format as time series` option **unchecked**) for the `Show` option select `All Values`.
- For time series data (`Format as time series` option **checked**) for the `Show` option select `Calculate` and choose a reducer function.
Expand All @@ -61,7 +61,7 @@ Configure the Gauge's `Value Options`, depending on your query.

Please refer to our [Documentation](https://developer.bitmovin.com/playback/docs/integrating-bitmovin-analytics-with-grafana) and [Analytics Api Reference](https://developer.bitmovin.com/playback/reference/overview) for more information or reach out to us at [bitmovin.com](https://bitmovin.com/contact-bitmovin/).

-----
---

## Development

Expand Down
40 changes: 10 additions & 30 deletions example_dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,7 @@
"value": "0"
}
],
"groupBy": [
"BROWSER"
],
"groupBy": ["BROWSER"],
"interval": "AUTO",
"license": "<YOUR-API-KEY>",
"metric": "count",
Expand Down Expand Up @@ -723,9 +721,7 @@
"value": "0"
}
],
"groupBy": [
"COUNTRY"
],
"groupBy": ["COUNTRY"],
"interval": "AUTO",
"license": "<YOUR-API-KEY>",
"metric": "count",
Expand Down Expand Up @@ -781,9 +777,7 @@
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"reducer": ["sum"],
"show": false
},
"showHeader": true
Expand All @@ -800,9 +794,7 @@
"value": "0"
}
],
"groupBy": [
"PLAYER_TECH"
],
"groupBy": ["PLAYER_TECH"],
"interval": "AUTO",
"license": "<YOUR-API-KEY>",
"metric": "count",
Expand Down Expand Up @@ -863,9 +855,7 @@
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"reducer": ["sum"],
"show": false
},
"showHeader": true
Expand All @@ -882,9 +872,7 @@
"value": "0"
}
],
"groupBy": [
"OPERATINGSYSTEM"
],
"groupBy": ["OPERATINGSYSTEM"],
"interval": "AUTO",
"license": "<YOUR-API-KEY>",
"limit": 10,
Expand Down Expand Up @@ -946,9 +934,7 @@
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"reducer": ["sum"],
"show": false
},
"showHeader": true
Expand All @@ -959,9 +945,7 @@
"datasource": {},
"dimension": "IMPRESSION_ID",
"filter": [],
"groupBy": [
"BROWSER"
],
"groupBy": ["BROWSER"],
"interval": "AUTO",
"license": "<YOUR-API-KEY>",
"limit": 10,
Expand Down Expand Up @@ -1023,9 +1007,7 @@
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"reducer": ["sum"],
"show": false
},
"showHeader": true
Expand All @@ -1036,9 +1018,7 @@
"datasource": {},
"dimension": "IMPRESSION_ID",
"filter": [],
"groupBy": [
"COUNTRY"
],
"groupBy": ["COUNTRY"],
"interval": "AUTO",
"license": "<YOUR-API-KEY>",
"limit": 10,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"typecheck": "tsc --noEmit",
"lint": "eslint --cache --ignore-pattern 'dist/**' --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "yarn run lint --fix",
"format": "yarn prettier . --write",
"format:check": "yarn prettier --check .",
"e2e": "yarn playwright test",
"server": "docker-compose up --build",
"sign": "npx --yes @grafana/sign-plugin@latest"
Expand Down
28 changes: 14 additions & 14 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add the plugin and acquire your Bitmovin Analytics API key from the [bitmovin da
Configure the datasource:

| Setting | Value |
|--------------|----------------------------------------------------------|
| ------------ | -------------------------------------------------------- |
| URL | `https://api.bitmovin.com/v1` |
| API Key | Your API key |
| Ad Analytics | If checked, the datasource is switched to query ads data |
Expand All @@ -27,18 +27,18 @@ See the [example_dashboard.json](example_dashboard.json) for a demo. Configure t
Add a new panel and select the bitmovin analytics datasource.
Configure the metric with following settings:

| Setting | Description |
|------------------------|------------------------------------------------------------------------------------------|
| License* | Your analytics license |
| Metric* | Aggregation method to use, e.g. `count`, `sum` |
| Dimension* | Dimension to aggregate over |
| Filter | Apply filters to the query |
| Format as time series* | Check the switch to see time series data |
| Group By | Group query by dimension and plot as individual time series |
| Order By | Order query ascending or descending by dimension |
| Limit | Limit the result to given number |
| Interval* | Time granularity of queries, select `AUTO` to automatically adapt to selected time range |
| Alias By | Set the name of series (only visible with multiple queries in one Graph) |
| Setting | Description |
| ----------------------- | ---------------------------------------------------------------------------------------- |
| License\* | Your analytics license |
| Metric\* | Aggregation method to use, e.g. `count`, `sum` |
| Dimension\* | Dimension to aggregate over |
| Filter | Apply filters to the query |
| Format as time series\* | Check the switch to see time series data |
| Group By | Group query by dimension and plot as individual time series |
| Order By | Order query ascending or descending by dimension |
| Limit | Limit the result to given number |
| Interval\* | Time granularity of queries, select `AUTO` to automatically adapt to selected time range |
| Alias By | Set the name of series (only visible with multiple queries in one Graph) |

Settings marked with `*` are required for the time series graph.

Expand All @@ -52,7 +52,7 @@ Configure the metric as described in [Time Series Graph](#time-series-graph) but

## Gauges

Configure the Gauge's `Value Options`, depending on your query.
Configure the Gauge's `Value Options`, depending on your query.

- For table data (`Format as time series` option **unchecked**) for the `Show` option select `All Values`.
- For time series data (`Format as time series` option **checked**) for the `Show` option select `Calculate` and choose a reducer function.
Expand Down
12 changes: 11 additions & 1 deletion src/components/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ export function QueryEditor(props: Props) {
};

const handleAggregationChange = (item: SelectableValue) => {
props.onChange({ ...query, metric: item.value });
// set a default value when percentile is selected and delete percentileValue when percentile is deselected
// to not pollute the dashboard.json file
let percentile = undefined;
if (item.value === 'percentile' && percentileValue == null) {
setPercentileValue(95);
percentile = 95;
} else {
setPercentileValue(undefined);
}

props.onChange({ ...query, metric: item.value, percentileValue: percentile });
props.onRunQuery();
};

Expand Down
18 changes: 13 additions & 5 deletions src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
} from '@grafana/data';
import { getBackendSrv } from '@grafana/runtime';
import { filter, isEmpty } from 'lodash';
// eslint-disable-next-line no-restricted-imports
import moment from 'moment';
import { catchError, lastValueFrom, map, Observable, of } from 'rxjs';

import {
Expand Down Expand Up @@ -88,6 +90,7 @@ export class DataSource extends DataSourceApi<
async query(options: DataQueryRequest<BitmovinAnalyticsDataQuery>): Promise<DataQueryResponse> {
const { range } = options;
const isRelativeRangeFrom = this.isRelativeRangeFrom(range.raw);
let momentTimeUnit = undefined;

//filter disabled queries
const enabledQueries = (options.targets = filter(options.targets, (t) => !t.hide));
Expand All @@ -101,7 +104,9 @@ export class DataSource extends DataSourceApi<
? calculateQueryInterval(target.interval, range!.from.valueOf(), range!.to.valueOf())
: undefined;

let queryFrom = range!.from;
// create new moment object to not mutate the original grafana object with startOf() to not change
// the grafana graph at this point as this would change the timeframe for all the following queries
let queryFrom = moment(range!.from.valueOf());
const queryTo = range!.to;

// floor the query start time to improve cache hitting
Expand All @@ -111,11 +116,9 @@ export class DataSource extends DataSourceApi<
// to allow higher granularity if interval is selected by user
flooringInterval = getSmallerInterval(interval, flooringInterval);
}
const momentTimeUnit = getMomentTimeUnitForQueryInterval(flooringInterval);
momentTimeUnit = getMomentTimeUnitForQueryInterval(flooringInterval);
if (momentTimeUnit != null) {
// range from is a moment and startOf is mutating moment object so this has a side effect to also change the
// grafana selected timeframe value which will adapt the grafana graph as well
queryFrom = range!.from.startOf(momentTimeUnit);
queryFrom.startOf(momentTimeUnit);
}
}

Expand Down Expand Up @@ -203,6 +206,11 @@ export class DataSource extends DataSourceApi<
});
});

// round down grafana start time to adjust the grafana graph and show first data point
if (momentTimeUnit != null) {
range.from.startOf(momentTimeUnit);
}

return Promise.all(promises).then((data) => ({ data }));
}

Expand Down
10 changes: 8 additions & 2 deletions src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
"large": "img/logo.svg"
},
"links": [
{"name": "Project site", "url": "https://github.com/bitmovin/analytics-grafana-datasource"},
{"name": "Apache License", "url": "https://github.com/bitmovin/analytics-grafana-datasource/blob/main/LICENSE"}
{
"name": "Project site",
"url": "https://github.com/bitmovin/analytics-grafana-datasource"
},
{
"name": "Apache License",
"url": "https://github.com/bitmovin/analytics-grafana-datasource/blob/main/LICENSE"
}
],
"screenshots": [],
"version": "%VERSION%",
Expand Down

0 comments on commit 17a5001

Please sign in to comment.