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

Macros $interval not correct parse #238

Closed
oleg-savko opened this issue Jul 13, 2020 · 1 comment · Fixed by #239, #250 or grafana/grafana-plugin-repository#690
Closed

Macros $interval not correct parse #238

oleg-savko opened this issue Jul 13, 2020 · 1 comment · Fixed by #239, #250 or grafana/grafana-plugin-repository#690

Comments

@oleg-savko
Copy link

oleg-savko commented Jul 13, 2020

When use custom interval (variable with type Interval) macros $interval not correct parsed.

In docs said that it should parsed to seconds:
$interval - replaced with selected "Group by a time interval" value (as a number of seconds)

but it doesnt.

plugin version: 2.0.1

Example artificial:
table:

create table mx_master.test_interval (
    d DateTime,
    x UInt32
) engine = Null;

query:

SELECT
    $timeSeries as t,
    count(x) * $interval
FROM $table t
where $timeFilter
GROUP BY t
ORDER BY t

parsed to:
SELECT (intDiv(toUInt32(d), 600) * 600) * 1000 as t, count(x) * 10m FROM mx_master.test_interval t where d >= toDateTime(1594047643) GROUP BY t ORDER BY t

expected result:
SELECT (intDiv(toUInt32(d), 600) * 600) * 1000 as t, count(x) * 600 FROM mx_master.test_interval t where d >= toDateTime(1594047643) GROUP BY t ORDER BY t

@Slach
Copy link
Collaborator

Slach commented Jul 13, 2020

;) as we figure out in telegram,
there is $interval is not a macro, it's a template variable with the same name as macro
and this template variable has type "Interval"

unfortunately, grafana core doesn't pass grafana specific template variable type to plugin during replacement

so, as workaround we should change variable type from "Interval" to "Query"
and use following SQL query for clickhouse datasource

SELECT (arrayJoin(variable) as x).1 AS __text, x.2 AS __value
FROM (
  SELECT
    arrayMap((x, y) -> (x, y),
        splitByChar(',', '1m,10m,30m,1h,6h,12h,1d,7d,14d,30d'),
        splitByChar(',', '60,600,1800,3600,21600,43200,86400,604800,1209600,2592000')
    ) AS variable
)

Slach added a commit that referenced this issue Jul 24, 2020
# 2.0.3 (2020-07-24)

## Enhancements:
* add setup notes for Grafana 7.x to README
* add SQL preprocessing logic on browser side with <% js code subset %>, #186, thanks @fgbogdan
* improve alerts query processing for use case when `query(query_name, from, to)` time range is less than visible dashboard time range, see #237
* improve alerts json parsing in golang part for case when we have string fields in response which interprets as series name, see #230
* properly parsing POST queries in golang part of plugin, #228, thanks @it1804


## Fixes:
* add Vagrantfile for statefull environment and allow to upgrade scenario like  grafana 7.1.0 + grafana-cli upgrade-all
  * fix #244
  * fix #243
* add multiple dashboard examples for github issues:
  * fix #240 
  * fix #135 
  * fix #245 
  * fix #238   
  * fix #232
  * fix #127
  * fix #141
Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Jul 24, 2020
## Enhancements:
* add setup notes for Grafana 7.x to README
* add SQL preprocessing logic on browser side with <% js code subset %>, Altinity/clickhouse-grafana#186, thanks @fgbogdan
* improve alerts query processing for use case when `query(query_name, from, to)` time range is less than visible dashboard time range, see Altinity/clickhouse-grafana#237
* improve alerts json parsing in golang part for case when we have string fields in response which interprets as series name, see Altinity/clickhouse-grafana#230
* properly parsing POST queries in golang part of plugin, Altinity/clickhouse-grafana#228, thanks @it1804

## Fixes:
* add Vagrantfile for statefull environment and allow to upgrade scenario like  grafana 7.1.0 + grafana-cli upgrade-all
  * fix Altinity/clickhouse-grafana#244
  * fix Altinity/clickhouse-grafana#243
* add multiple dashboard examples for github issues:
  * fix Altinity/clickhouse-grafana#240
  * fix Altinity/clickhouse-grafana#135
  * fix Altinity/clickhouse-grafana#245
  * fix Altinity/clickhouse-grafana#238
  * fix Altinity/clickhouse-grafana#232
  * fix Altinity/clickhouse-grafana#127
  * fix Altinity/clickhouse-grafana#141

Signed-off-by: Eugene Klimov <eklimov@altinity.com>
Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Aug 13, 2020
# 2.1.0 (2020-08-13)

## Enhancement:
* add "Skip comments" checkbox to query editor to pass SQL comments to server, fix Altinity/clickhouse-grafana#265
* add setup notes for Grafana 7.x to README
* add SQL preprocessing logic on browser side with <% js code subset %>, Altinity/clickhouse-grafana#186, thanks @fgbogdan
* improve alerts query processing for use case when `query(query_name, from, to)` time range is less than visible dashboard time range, see Altinity/clickhouse-grafana#237
* improve alerts json parsing in golang part for case when we have string fields in response which interprets as series name, see Altinity/clickhouse-grafana#230
* properly parsing POST queries in golang part of plugin, Altinity/clickhouse-grafana#228, thanks @it1804

## Fixes:
* fix corner cases for $macro + subquery, see Altinity/clickhouse-grafana#276 and Altinity/clickhouse-grafana#277
* fix parallel query execution, see Altinity/clickhouse-grafana#273
* fix identifiers quotes, see Altinity/clickhouse-grafana#276, Altinity/clickhouse-grafana#277
* fix plugin.json for pass `grafana-plugin-repository` plugin validator
* fix multi-value variables behavior - Altinity/clickhouse-grafana#252
* add Vagrantfile for statefull environment and allow to upgrade scenario like  grafana 7.1.0 + grafana-cli upgrade-all
  * fix Altinity/clickhouse-grafana#244
  * fix Altinity/clickhouse-grafana#243
* add multiple dashboard examples for github issues:
  * fix Altinity/clickhouse-grafana#240
  * fix Altinity/clickhouse-grafana#135
  * fix Altinity/clickhouse-grafana#245
  * fix Altinity/clickhouse-grafana#238
  * fix Altinity/clickhouse-grafana#232
  * fix Altinity/clickhouse-grafana#127
  * fix Altinity/clickhouse-grafana#141

Signed-off-by: Eugene Klimov <eklimov@altinity.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants