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

adhoc is not working in latest grafana and latest plugin #282

Closed
nitzan-tz opened this issue Aug 27, 2020 · 6 comments · Fixed by #289 or grafana/grafana-plugin-repository#803
Closed
Assignees

Comments

@nitzan-tz
Copy link

Hi,

I have adhoc variable and I have a query that include WHERE with $adhoc
I am using Grafana v7.1.5 and Clickhouse plugin 2.1.0
I have this adhoc filter
default.flows_raw.SrcAS=1299
But the $adhoc is always 1

SELECT
    $timeSeries as t,
    count()
FROM $table
WHERE $timeFilter AND $adhoc
GROUP BY t
ORDER BY t

It is translated to

SELECT
    (intDiv(toUInt32(TimeFlowStart), 15) * 15) * 1000 as t,
    count()
FROM default.flows_raw
WHERE TimeFlowStart >= toDateTime(1598530090) AND 1
GROUP BY t
ORDER BY t
@Slach
Copy link
Collaborator

Slach commented Aug 28, 2020

@nitzan-tz could you share screenshot or part of dashboard JSON which could explain how exactly you define "ad-hoc" filters?
could you look to https://github.com/Vertamedia/clickhouse-grafana/blob/master/docker/grafana/dashboards/clickhouse_dashboard.json#L1405
these ad-hoc filters work as expected

I will try to reproduce your case ASAP

@Slach Slach self-assigned this Aug 28, 2020
@nitzan-tz
Copy link
Author

@Slach here is the json of the adhoc filter

"templating": { "list": [ { "datasource": "ClickHouse", "filters": [ { "condition": "", "key": "default.flows_raw.SrcAS", "operator": "=", "value": 1299 } ], "hide": 0, "label": "", "name": "adhoc_filter_example", "skipUrlSync": false, "type": "adhoc" } ] },

@Slach
Copy link
Collaborator

Slach commented Sep 2, 2020

@nitzan-tz could check the latest master branch version of plugin?
also, could you share a full JSON for your dashboard and CREATE TABLE statements if your error still reproduce?
I checked source code
only one place where we can replace $adhoc to 1
https://github.com/Vertamedia/clickhouse-grafana/blob/master/src/sql_query.ts#L100-L103
and adhocCondition fills only in
https://github.com/Vertamedia/clickhouse-grafana/blob/master/src/sql_query.ts#L80

so, in your case, maybe something wrong with ad-hoc filters and they didn't pass to SqlQuery.replace

@nitzan-tz
Copy link
Author

I have tried with the lates master branch but I see the same issue
I saw this error in Chrome and Firefox debugging (Line 81 is one line after the adhocCondition )

module.js:2 AST parser error:  TypeError: e.value.indexOf is not a function
    at eval (sql_query.ts:81)
    at Array.forEach (<anonymous>)
    at Ca.replace (module.js:2)
    at Va.createQuery (datasource.ts:164)
    at eval (datasource.ts:114)
    at a (_arrayMap.js:16)
    at xt (map.js:49)
    at Va.query (module.js:2)
    at runRequest.ts:154
    at E (runRequest.ts:104)

This is the create table

CREATE TABLE IF NOT EXISTS flows_raw
    (
        Date Date,
        TimeReceived DateTime,
        TimeFlowStart DateTime,
        SequenceNum UInt32,
        SamplingRate UInt64,
        SamplerAddress FixedString(16),
        SrcAddr FixedString(16),
        DstAddr FixedString(16),

        SrcAS UInt32,
        DstAS UInt32,

        InIf UInt32,
        OutIf UInt32,

        IPTos UInt32,
        ForwardingStatus UInt32,
        IPTTL UInt32,
        TCPFlags UInt32,
        IcmpType UInt32,
        IcmpCode UInt32,
        IPv6FlowLabel UInt32,

        EType UInt32,
        Proto UInt32,

        SrcPort UInt32,
        DstPort UInt32,

        Bytes UInt64,
        Packets UInt64
    ) ENGINE = MergeTree()
    PARTITION BY Date
    ORDER BY TimeReceived

This is the dashboard

dashboard-with-adhoc.json.txt

@Slach
Copy link
Collaborator

Slach commented Sep 10, 2020

@nitzan-tz could you check master again and report if still reproduce?

@nitzan-tz
Copy link
Author

@Slach it is working now
Thanks for your effort

Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Nov 30, 2020
# 2.2.0 (2020-11-30)
## Enhancement:

* add region support to annotation query, try to fix wrong column orders for table format, fix Altinity/clickhouse-grafana#303
* add plugin sign process, fix Altinity/clickhouse-grafana#212
* add `DateTime64` support, fix Altinity/clickhouse-grafana#292
* add `linux\arm64` backend plugin build
* improve ARRAY JOIN parsing, fix Altinity/clickhouse-grafana#284
* improve `docker-compose.yaml` add ability to redefine `GRAFANA_VERSION` and `CLICKHOUSE_VERSION` via environment variables `latest` by default

## Fixes:
* add `*.js.map` and `*.js` from src and spec folder to .gitignore
* don't apply adhoc filters twice when used $adhoc macros, fix Altinity/clickhouse-grafana#282
* fix corner case for table format with wrong columns order between meta and data response section, fix Altinity/clickhouse-grafana#281
* add trickster to docker-compose environment
* actualize links in README.md

Signed-off-by: Eugene Klimov <[email protected]>
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