Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cognite/grafana-migration-script

Package Overview
Dependencies
Maintainers
107
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cognite/grafana-migration-script

This script can be used to migrate existing Grafana dashboards from CDF Grafana plugin v1.0.x to v2.0.0

  • 0.0.16
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
107
Weekly downloads
 
Created
Source

Grafana dashboard migration script

This script can be used to migrate existing Grafana dashboards from CDF Grafana plugin v1.0.x to v2.0.0

Requirements

  1. Grafana instance with Cognite Data Fusion plugin v1.0.x
  2. Grafana api key with admin access.
  3. CDF Api keys for the projects used on the instance (with capabilities: timeseriesAcl:READ). Note: You don't need to know project names in advance, script will ask for them itself.
  4. Any computer with nodejs v10 installed. The script uses APIs and doesn't need to be executed directly from the instance.

Step #0

Upgrade Cognite datasource plugin to v2.0.0+

Step #last

run npx @cognite/grafana-migration-script --grafanaUrl <grafana-url> --grafanaApiKey <grafana-api-key>

where:

<grafana-url> – url to your Grafana instance (E.g. "http://localhost:3000")

<grafana-api-key> – token that you need to generate from your Grafana instance. Check Grafana Documentation (E.g. eyJrIj...oxfQ==). Api key is always attached to a specific organisation. In order to migrate multiple organisations you need to execute npx @cognite/grafana-migration-script for each api key.

Optional flags: --rollback – to revert changes caused by migration script --dryRun – to test migration script without writing back to grafana instance

Note: npx comes bundled with nodejs, no installation required.

  1. After that you'll be prompted for Cognite API-key for each project. Enter API-keys one by one, or leave the field empty to skip specific project.

After successful script execution you should see those kind of messages in console output:

dashboard-name – status: SUCCESS

The script will also print difference between dashboard JSON configurations.

Debugging

If something goes wrong during migration there are a few options to do.

  1. If dashboards are severely damaged the easiest way would be to revert them back to previous state. Execute: node dist/main.js --grafanaUrl <grafana-url> --grafanaApiKey <grafana-api-key> --rollback Note: avoid executing this too many times, grafana has a limit for amount of stored versions (default: 20)
  2. If minor issues where discovered, it might be better to fix them by editing via Grafana UI. After each script execution debug-[[timestamp]].log is created. This file contains error messages and JSON diffs, so you can use it in order to manually fix broken dashboards.
  3. If any questions, please contact our support team on slack or via support@cognite.com.

Under the hood

This script translates JSON dashboards configuration from CDF Grafana plugin syntax v1.0.x to v2.0.0.

Changes

Time series changes
  • target: [timeseries_name] replaced with corresponding timeseries id
  • custom queries syntax changes
Featurev1.0.xv2.0.0
Root assetValue from input fieldPart of a custom query filter syntax. E.g. ts{assetSubtreeIds=[{id=ASSET_ID}]}
Time series reference[ID] or [ID, AGGREGATE, GRANULARITY]ts{id=TS_ID} or ts{id=TS_ID, aggregate='AGGREGATE', granularity="GRANULARITY"}
Filter with aggregatestimeseries{}[AGGREGATE, GRANULARITY]ts{aggregate='AGGREGATE', granularity='GRANULARITY'}
Name filtertimeseries{name='TS_NAME'}ts{externalId=TS_EXT_ID} or ts{id=TS_ID}
Name RegExp filtertimeseries{name=~'.*regex.*'}ts{name=~'.*regex.*'}
Metadata filterstimeseries{metadata.type=~'.*well.*', metadata.tag='1'}ts{metadata={type=~'.*well.*', tag='1'}}
Math functionssum, max, min, avg, pow, sin, cos, pi, sqrt, abs, exp, ln, round. E.g. sum(timeseries{}) or SUM(timeseries{})Lower-cased. E.g. sum(ts{}). In addition power is converted to pow
Unsupported functionsacos, asin, atan, ceil, cot, degrees, floor, log, log2, log10, radians, sign, tan, atan2, mod, truncateOmitted by the script, not supported in API v1
Aggregation shortcutsavg, int, step, cv, dv, tvChanged to full versions: average, interpolation, stepInterpolation, continuousVariance, discreteVariance, totalVariation. If these were used in variables, like [TS_ID, $aggregate] the script will try to migrate them as well.
Non-quoted filterstimeseries{description=VAL}ts{description="VAL"}

Custom queries use synthetic time series feature from API v1. Use this link to find out more about synthetics.

Template variable changes
  • query and filter fields replaced with all-in-one query. Instead of separate asset{} and filter{} same result can be achieved with assets{} syntax.
Featurev1.0.xv2.0.0
Asset sub-treesasset{assetSubtrees=[ID1,ID2]}assets{assetSubtreeIds=[{id=ID1}, {externalId='EXT_ID2'}]}
Metadata queryasset{metadata={"key": "VAL1", "key2": "VAL2"}}assets{metadata={key='VAL1', key2='VAL2'}}
Timestamps queryFilters: minCreatedTime, maxCreatedTime, minLastUpdatedTime, maxLastUpdatedTime. E.g. asset{lastUpdatedTime=0}Similar to API v1 assets{lastUpdatedTime={min=0, max=1}}}
Filterfilter{name=~".*"}Now is a part of the query: assets{name=~'.*'}
Unsupported propertiessort, dir, offset, boostNameNot supported, the script will remove them from query
Annotation changes

Similar to templates query and filter fields replaced with one query. Instead of separate event{} and filter{} new events{} syntax is used.

Filtering syntax is changed the same way as for template variables, use the comparison table above for examples.

Other JSON changes
  • Properties removed: func, assetQuery.templatedTarget, assetQuery.func, assetQuery.timeseries
  • target: 'Start typing tag id here' replaced with an empty string

FAQs

Package last updated on 27 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc