Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: template variables and annotations for API v1 #94

Merged
merged 15 commits into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"author": "Cognite AS",
"license": "Apache-2.0",
"scripts": {
"build": "webpack --config webpack.config.prod.js",
"build": "yarn build-query-parser && webpack --config webpack.config.prod.js",
"dev": "webpack --config webpack.config.js --mode development",
"dev:watch": "webpack --config webpack.config.js --mode development --watch",
"run-docker": "docker build -t cognite-grafana . && docker run --rm -it -p 3000:3000 cognite-grafana",
"test": "jest --coverage",
"test:debug": "node --inspect node_modules/.bin/jest --runInBand",
"tslint": "tslint -c tslint.json --project tsconfig.json",
"tslint:fix": "tslint -c tslint.json --project tsconfig.json --fix",
"prettier": "prettier --write \"src/**/*.{ts,tsx,js,json,css,md}\""
"prettier": "prettier --write \"src/**/*.{ts,tsx,js,json,css,md}\"",
"build-query-parser": "nearleyc ./src/query-parser/grammar.ne -o ./src/query-parser/grammar.ts"
},
"devDependencies": {
"@grafana/ui": "^6.0.1-alpha.0",
Expand All @@ -29,10 +30,12 @@
"clean-webpack-plugin": "^1.0.1",
"copy-webpack-plugin": "^4.6.0",
"css-loader": "^2.1.0",
"deepdash": "^4.5.4",
"husky": "^1.3.1",
"jest": "23",
"lint-staged": "^8.1.1",
"ms": "^2.1.2",
"nearley": "^2.19.1",
"ng-annotate-webpack-plugin": "^0.3.0",
"prettier": "1.16.3",
"query-string": "^6.10.1",
Expand All @@ -54,7 +57,7 @@
},
"lint-staged": {
"*.{ts,tsx,js,json,css}": [
"tslint -c tslint.json --fix",
"tslint -c tslint.json --fix -e \"grammar.ts\"",
polomani marked this conversation as resolved.
Show resolved Hide resolved
"prettier --write",
"git add"
],
Expand Down
154 changes: 20 additions & 134 deletions src/__tests__/__snapshots__/annotations.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ exports[`Annotations Query Given an annotation query should generate the correct
Object {
"data": Object {
"filter": Object {
"assetIds": "[123]",
"assetIds": Array [
123,
],
"endTime": Object {
"min": 1549336675000,
},
Expand All @@ -20,31 +22,6 @@ Object {
}
`;

exports[`Annotations Query Given an annotation query should return the correct events 1`] = `
Array [
Object {
"annotation": Object {
"expr": "event{assetIds = [123], type= 'type 1' }",
},
"isRegion": true,
"text": "event 1",
"time": "1549336675000",
"timeEnd": "1549336775000",
"title": "type 1",
},
Object {
"annotation": Object {
"expr": "event{assetIds = [123], type= 'type 1' }",
},
"isRegion": true,
"text": "time out of bounds",
"time": "1549336600000",
"timeEnd": "1549338500000",
"title": "type 1",
},
]
`;

exports[`Annotations Query Given an annotation query where nothing is returned should generate the correct request 1`] = `
Object {
"data": Object {
Expand All @@ -71,7 +48,10 @@ Object {
"endTime": Object {
"min": 1549336675000,
},
"metadata": "{\\"key1\\":\\"value1\\",\\"key2\\":\\"value2\\"}",
"metadata": Object {
"key1": "value1",
"key2": "value2",
},
"startTime": Object {
"max": 1549338475000,
},
Expand All @@ -83,19 +63,16 @@ Object {
}
`;

exports[`Annotations Query Given an annotation query with a metadata request should return the correct event 1`] = `
Array [
Object {
"annotation": Object {
"expr": "event{ metadata={\\"key1\\":\\"value1\\",\\"key2\\":\\"value2\\"} }",
},
"isRegion": true,
"text": "time out of bounds",
"time": "1549336600000",
"timeEnd": "1549338500000",
"title": "type 1",
},
]
exports[`Annotations Query Given an annotation query with an incomplete event expression should throw a parse error 1`] = `
"Parser: Unexpected end of input:
events{
^"
`;

exports[`Annotations Query Given an annotation query with an incorrect event expression should throw a parse error 1`] = `
"Parser: Syntax error:
events{ name=~event, foo}
^"
`;

exports[`Annotations Query Given an annotation query with filters should generate the correct request 1`] = `
Expand All @@ -116,49 +93,13 @@ Object {
}
`;

exports[`Annotations Query Given an annotation query with filters should return the correct events 1`] = `
Array [
Object {
"annotation": Object {
"expr": "event{}",
"filter": "filter{description=~event.*, type!= 'type 1', }",
},
"isRegion": true,
"text": "event 2",
"time": "1549336775000",
"timeEnd": "1549336875000",
"title": "type 2",
},
Object {
"annotation": Object {
"expr": "event{}",
"filter": "filter{description=~event.*, type!= 'type 1', }",
},
"isRegion": true,
"text": "event 3",
"time": "1549336875000",
"timeEnd": "1549336975000",
"title": "type 3",
},
Object {
"annotation": Object {
"expr": "event{}",
"filter": "filter{description=~event.*, type!= 'type 1', }",
},
"isRegion": true,
"text": "event 4",
"time": "1549336975000",
"timeEnd": "1549337075000",
"title": "type 4",
},
]
`;

exports[`Annotations Query Given an annotation query with variables should generate the correct request 1`] = `
Object {
"data": Object {
"filter": Object {
"assetIds": "[123]",
"assetIds": Array [
123,
],
"endTime": Object {
"min": 1549336675000,
},
Expand All @@ -174,58 +115,3 @@ Object {
`;

exports[`Annotations Query Given an annotation query with variables should return the correct events 1`] = `Array []`;

exports[`Annotations Query Given an annotation query without any filters should return all events 1`] = `
Array [
Object {
"annotation": Object {
"expr": "event{}",
},
"isRegion": true,
"text": "event 1",
"time": "1549336675000",
"timeEnd": "1549336775000",
"title": "type 1",
},
Object {
"annotation": Object {
"expr": "event{}",
},
"isRegion": true,
"text": "event 2",
"time": "1549336775000",
"timeEnd": "1549336875000",
"title": "type 2",
},
Object {
"annotation": Object {
"expr": "event{}",
},
"isRegion": true,
"text": "event 3",
"time": "1549336875000",
"timeEnd": "1549336975000",
"title": "type 3",
},
Object {
"annotation": Object {
"expr": "event{}",
},
"isRegion": true,
"text": "event 4",
"time": "1549336975000",
"timeEnd": "1549337075000",
"title": "type 4",
},
Object {
"annotation": Object {
"expr": "event{}",
},
"isRegion": true,
"text": "time out of bounds",
"time": "1549336600000",
"timeEnd": "1549338500000",
"title": "type 1",
},
]
`;
Loading