@ [Anaisdg]
Can someone please help me to convert my old InfluxQL query to Flux query?
These query is being used in Grafana-7.x and InfluxDB 2.x.
InfluQL Query : SELECT mean(“value”) FROM /container.ops.*/ WHERE “environment” = ‘$env’ AND “region” =~ /^(?i)$region$/ AND “container” =~ /(?i)$container/ AND $timeFilter GROUP BY time($__interval) fill(null)
I tried below, but it’s not working as intended and i may be way off.
Hello @Artificial_Brain,
It’s hard for me to understand how I can fix the regex without knowing what values you want to receive.
Are you aware of the strings package?
@Artificial_Brain,
Can you describe what you’re trying to filter for with regex so I can help you craft the correct regex? I find using a regex tester like
I don’t want to put below hard coded values, this making query running very slow and spacious too.
|> filter(fn: (r) => r["_measurement"] == “container.ops.data.issueRates” or r["_measurement"] == “container.ops.data.ratePersmissions” or r["_measurement"] == “container.ops.data.financialSteps” or r["_measurement"] == “container.ops.data.examineDepth” or r["_measurement"] == “container.ops.data.localPayment” or r["_measurement"] == “container.ops.data.globalWellness” …so on )
|> filter(fn: (r) => r[“container”] == “PO-PS-ALOCA_AIRIAN” or r[“container”] == “PO-PS-ALOCA_CQPRXN” or r[“container”] == “PO-PS-ALOCA_FBSELO” or r[“container”] == “PO-PS-ALOCA_JSBORKF” or r[“container”] == “PO-PS-ALOCA_HBWSHJI” or r[“container”] == “PO-PS-ALOCA_NREPXL”)
|> filter(fn: (r) => r[“environment”] == “BETA” or r[“environment”] == “DEV” or r[“environment”] == “PROD” or r[“environment”] == “QA”)
|> filter(fn: (r) => r[“region”] == “rams” or r[“region”] == “paca” or r[“region”] == “manoa” or r[“region”] == “lapea”)
Hello @Artificial_Brain,
Yes I understand why you need regex. Thanks for sharing your original query so we can find the right regex. Alternatively I suggest using the string package shared above instead of regex as it might be easier but here’s a regex solution.
|> filter(fn: (r) => r["_measurement"] =~ /^container.ops.data./)
|> filter(fn: (r) => r["container"] =~ /^PO-PS-ALOCA_/)
|> filter(fn: (r) => r[“environment”] == “BETA” or r[“environment”] == “DEV” or r[“environment”] == “PROD” or r[“environment”] == “QA”)
|> filter(fn: (r) => r[“region”] == “rams” or r[“region”] == “paca” or r[“region”] == “manoa” or r[“region”] == “lapea”)
The issue being ^(?i)$ matches an empty string, but the additional <string>$ prevents it from matching anything. I don’t understand why grafana is generating those regex.