Skip to content

Instantly share code, notes, and snippets.

@cosh
Created July 19, 2019 07:25
Show Gist options
  • Save cosh/a68190e0d5090ae13f5865bddfce962c to your computer and use it in GitHub Desktop.
Save cosh/a68190e0d5090ae13f5865bddfce962c to your computer and use it in GitHub Desktop.
DDL for prometheus to ADX
//Table for raw data and the corresponding mapping
.create table RawData (d: dynamic)
.create table RawData ingestion json mapping "RawDataMapping" '[{ "column" : "d", "datatype" : "dynamic", "path" : "$"}]'
//Table for the remote_read endpoint (optimized for quering time series and labels.
.create table SearchExplosion (ts: datetime, label: dynamic, timeseries: dynamic, value: real)
//Update policy RawData -> SearchExplosion
.create function Update_SearchExplosion()
{
RawData
| extend id = new_guid()
| mv-expand d.Samples
| extend value=todouble(d_Samples.Value), ts=datetime(1970-01-01) + tolong(d_Samples.Timestamp)*1ms, labels=d.Labels
| project-away d_Samples
| mv-expand labels
| extend label=tostring(labels.Name), labelValue=tostring(labels.Value)
| project-away labels
| extend p = pack(label, labelValue)
| summarize label=make_bag(p), timeseries=any(d), value=any(value) by ['id'], ts
| project-away ['id']
}
//Adding the policy
.alter table SearchExplosion policy update
@'[{"IsEnabled": true, "Source": "RawData", "Query": "Update_SearchExplosion()", "IsTransactional": false, "PropagateIngestionProperties": false}]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment