@cognite/grafana-migration-script

    0.0.25 • Public • Published

    Grafana dashboard migration script

    This script can be used to migrate existing Grafana dashboards from CDF Grafana plugin v1.0.x to v2.1.x+ Note: this script is not compatible with the plugin v2.0.0/v2.0.1. Consider upgrading to v2.1.0 directly.

    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
    Feature v1.0.x v2.0.0
    Root asset Value from input field Part 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 aggregates timeseries{}[AGGREGATE, GRANULARITY] ts{aggregate='AGGREGATE', granularity='GRANULARITY'}
    Name filter timeseries{name='TS_NAME'} ts{externalId=TS_EXT_ID} or ts{id=TS_ID}
    Name RegExp filter timeseries{name=~'.*regex.*'} ts{name=~'.*regex.*'}
    Metadata filters timeseries{metadata.type=~'.*well.*', metadata.tag='1'} ts{metadata={type=~'.*well.*', tag='1'}}
    Math functions sum, 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 functions acos, asin, atan, ceil, cot, degrees, floor, log, log2, log10, radians, sign, tan, atan2, mod, truncate Omitted by the script, not supported in API v1
    Aggregation shortcuts avg, int, step, cv, dv, tv Changed 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 filters timeseries{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.
    Feature v1.0.x v2.0.0
    Asset sub-trees asset{assetSubtrees=[ID1,ID2]} assets{assetSubtreeIds=[{id=ID1}, {externalId='EXT_ID2'}]}
    Metadata query asset{metadata={"key": "VAL1", "key2": "VAL2"}} assets{metadata={key='VAL1', key2='VAL2'}}
    Timestamps query Filters: minCreatedTime, maxCreatedTime, minLastUpdatedTime, maxLastUpdatedTime. E.g. asset{lastUpdatedTime=0} Similar to API v1 assets{lastUpdatedTime={min=0, max=1}}}
    Filter filter{name=~".*"} Now is a part of the query: assets{name=~'.*'}
    Unsupported properties sort, dir, offset, boostName Not 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

    Keywords

    none

    Install

    npm i @cognite/grafana-migration-script

    DownloadsWeekly Downloads

    26

    Version

    0.0.25

    License

    Apache-2.0

    Unpacked Size

    1.91 MB

    Total Files

    4

    Last publish

    Collaborators

    • derek-reilly
    • lokaltog
    • cemreyavuz
    • trondeh80
    • parami.abeysekara
    • sumitpandey
    • francisco.rull
    • rhuan.barreto
    • neringaalt
    • dordev
    • alexnix
    • drsp-cognite
    • alitahir11
    • oiuytrdsxcvbnjkhgfcvbnm
    • wjoel
    • tapped
    • mortencognite
    • frxstrem
    • cognitecicd
    • pavelzubarev
    • msusag
    • nfremming
    • ktjolsen
    • kiriencognite
    • mperzyna
    • steinhdan
    • dmivankov
    • polomani
    • simen.eriksen
    • joma_cognite
    • nildo
    • sjinyuan
    • nils-cognite
    • dlcognite
    • haak
    • carlospereira
    • issaafkattan
    • larsmoa
    • nishafern
    • trygve.utstumo
    • bellamoo
    • kylling
    • kathrine-cognite
    • roman010
    • kimjoar
    • rekarnar
    • maximcognite
    • rumeshwick
    • tim-othy
    • vegardokland
    • hhenriques
    • tfheen-cognite
    • oksana_korniienko
    • j-bjorne
    • scottmelhop
    • magnusmoan
    • mathialo
    • agadacz-cognite
    • paulo-menezes-cognite
    • miladcognite
    • me-ydv-5
    • cogniteterraform
    • anderscognite
    • fredrik955
    • valgussev
    • halvard
    • dan.levings.cognite
    • sindresh92
    • christjt
    • maksim.nesterenko
    • hakontro
    • arnekv
    • jucc
    • ana-gheorghe
    • matthew.cameron
    • pbettler
    • anttran
    • dsaks999
    • qtiptip
    • cognite-joa
    • sceniclife
    • johan-cognite
    • theresatalor-cognite
    • mspang
    • eliasbjorne
    • oysteinolsen
    • arvearve
    • anders-cog
    • skairunner
    • siljec
    • nicklassvendsrud
    • jtcog
    • petmotzf
    • thorkild
    • deep-cognite
    • mattmurph9
    • lprovensi
    • haakonflatval-cognite
    • henne90gen-cognite
    • nicolasagnes
    • begozcan
    • eiriklv
    • valeriia-prokopenko
    • khalzmax
    • chingyu-cognite
    • mikaelcognite
    • sighol
    • lisa.halvorsen.cognite
    • heiding
    • ronald-cognite
    • senickel
    • sachila
    • daniel.priori
    • ravinda-cognite
    • timurgen
    • trodden-dev
    • podeig-cognite
    • aryna.karali
    • emel.varol
    • bdimitrijoski
    • madskjeldsberg
    • yevhenii.maltsev
    • farrukk24
    • aurlien
    • bianca-mv
    • samarv
    • soleh23
    • malindakpt
    • mihilr
    • gayandeegala
    • tfarvac
    • d0ttir
    • borajimin
    • marielha
    • samir-ajdarpasic
    • torbjornopheim
    • chanaka25
    • geircognite
    • soumesh.banerjee
    • mohsin.cognite
    • asankad.cog
    • vebjorngilberg
    • roligheten
    • marcushorn
    • sara.aalbu
    • atussa
    • aizumi
    • therockvalley
    • fgcognite
    • krzysztof-olbinski
    • gleb.kaistro
    • lasse.alm
    • dmitrijs.rutko.cognite
    • perarnet
    • denys-kseniev-cognite
    • bisera
    • shehan.cognite
    • udara-cognite
    • raabyeeggs
    • sennen-cognite
    • asankad
    • jarlah
    • keepfloyding
    • kbsaid
    • nayang-cognite
    • stevenhgnguyen
    • cgustad
    • haved
    • ttmcswg
    • cognitehumlen
    • tommy_thorsen
    • andersfylling
    • meisammalekzadeh
    • ericbrattli
    • mcarun
    • saagar-cognite
    • waqasjaved1