-
Notifications
You must be signed in to change notification settings - Fork 121
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
Tables have wrong columns if ClickHouse JSON datapoint is not ordered #281
Tables have wrong columns if ClickHouse JSON datapoint is not ordered #281
Comments
@genzgd thanks a lot for reporting |
Just reporting that we also have the same problem. We proxy clickhouse queries through a http layer and the json response produced by the proxy layer isn't necessarily in the same order as the select clause. This causes the table to have wrong data under the wrong columns. |
@ashutoshraina do you mean "trickster" proxy or "proxy mode" in clickhouse data source? |
We have a separate proxy written in go. We point the datasource to that proxy. The query comes back with the expected JSON but rendering of the table is incorrect due to the reasons mentioned above.
|
@genzgd could you share your |
@ashutoshraina could you explain what exactly wrong? as I see on your screenshot everything looks fine, table have same column order as described in response |
Trickster config -- we run trickster against an nginx proxy in Kubernetes.
I am the primary author of the ClickHouse support for Trickster. I am very familiar with how cached queries are stored, using standard GoLang JSON support, and I know that order of properties is not preserved. We see the same results as @ashutoshraina -- the columns on the screenshot are in the correct order, but the data is from different columns. So if we have column b, c, d, a in our query and metadata, the resulting data comes back as a,b,c,d in each JSON object and that's how the table columns are populated. |
@Slach Exactly what @genzgd mentioned. If the meta and data keys are not in the same order then the table columns are not populated correctly. |
@Slach Is there some more information I can provide to help move this forward ? Just to improve my understanding of the codebase, would the following be test case that should pass ( it currently fails ).
|
@ashutoshraina thanks a lot for testcase i will fix it ASAP |
@ashutoshraina hmm, look like your test case PASSED currently, on latest |
@genzgd as I see |
@genzgd and @ashutoshraina Currently after run
and open in browser http://localhost:3000/d/2LfUU3vMz/trickster-dashboard?orgId=1 maybe I do something wrong?
I can't figure out, was request from grafana to trickster:8480 cached or not |
Correct, Trickster does nothing with POSTs but pass them through. With a GET you can tell if the response is cached by looking at the special header coming back. Unfortunately it isn't currently caching correctly with the newest Plugin version, because of the additional wrapping of the $timeFilter variable in another level of parens (I'm working on fixing that now). When it does work you can see the result in the |
@genzgd i got following results for my environment |
Because the X-Trickster-Result is "proxy-only", Trickster did not cache this result but just returned the unchanged result fro ClickHouse. You need to send a query in that looks like a time series query and send it twice, so that the second response comes from the Trickster cache and gets recreated instead of coming directly from ClickHouse. This is the sample query I use in the unit tests that should get cached: |
Also just a reminder that the Grafana plugin works for charts, it seems that only tables are broken. |
@genzgd I can't catch cache behavior from trickster with change column orders I trying to send following curl request: curl 'http://localhost:3000/api/datasources/proxy/4/?query=SELECT%0A%20%20%20%20(intDiv(toUInt32(event_time)%2C%2030)%20*%2030)%20*%201000%20as%20t%2C%0A%20%20%20%20count()%20AS%20b%2C%0A%20%20%20%20sum(t%20%25%20100000)%20AS%20a%0AFROM%20default.test_grafana%0A%0AWHERE%20event_time%20%3E%3D%20toDateTime(1599735563)%0A%0AGROUP%20BY%20t%0A%0AORDER%20BY%20t%20FORMAT%20JSON' -H 'accept: application/json' -H 'Cookie: grafana_session=0cf3e63f193d25e2828bfde0aa267b1e' --compressed -i -vvv first time I got
and {
"meta":[
{"name":"t","type":"UInt64"},
{"name":"b","type":"UInt64"},
{"name":"a","type":"UInt64"}
],
"data":[
{"t":"1599735540000","b":"3","a":"120000"}
...
]} second time
with same JSON results {
"meta":[{"name":"t","type":"UInt64"},{"name":"b","type":"UInt64"},{"name":"a","type":"UInt64"}],
"data":[{"t":"1599735540000","b":"3","a":"120000"} ... ]
} what I should do to reproduce errornomus behavior? |
@genzgd could you suggest to me how I can trigger change columns order behavior in trickster? |
I'll try to find time to reproduce this; it's been a busy few days. Regardless, I think @ashutoshraina has identified the code that causes the problem. Because the plugin uses the order of JSON properties instead of their names, and the order of JSON properties is not guaranteed, the plugin is broken. You could just create an artificial response with "out of order" properties to test a fix. |
@genzgd, hmm, as I see @ashutoshraina found https://github.com/Vertamedia/clickhouse-grafana/blob/master/src/response_parser.ts#L30 but this part of code is executed only when we have
and indexes so, for common case when we can try to look at so look like "wrong" data transformation happens on Grafana TABLE plugin, cause you said "graph" panels works fine |
@Slach I think my test may be incorrect. I need your help in understanding if the test I submitted is correct or not. What is the expected size of the array res for the test case I submitted ? Should it be 2 ? Here's what I am thinking and please do let me know if this does not make sense. sqlResults (https://github.com/Vertamedia/clickhouse-grafana/blob/master/src/response_parser.ts#L21) will have two entries based on the input in the test and we are adding each element of the sqlResults array to the res array. My test passes with array containing one element. Should there be a data[0] with key as bar and data[1] with key as foo ( or the other way around? |
Just bumping this up. |
@ashutoshraina thanks a lot for your attention I going to try to fix it on next week |
In case this helps I have tried multiple versions of grafana and plugins and the issue was reproducible every time in both. 7.0.6 - Grafana with Clickhouse Plugin 1.9.1 |
@ashutoshraina, unfortunately, I can't reproduce JSON with different order with @genzgd could you help us trigger this behavior with trickster?
open |
I'll try to take a look, but the fragile ClickHouse "time series" parsing in the current version of Trickster is currently broken (by the addition of an extra set of parentheses around the $timeFilter expression), and I've not had time to fix it. What query does that dashboard use? |
@genzgd sorry for the late response, this dashboard uses a simple query with two time-series
and i can't reproduce trickster behavior when "a" and "b" switched values in JSON cached response from trickster steps to reproduce
|
I tried to repro this as well using the steps mentioned. I wasn't able to do that.
I think there might be another way of trying to repro this. |
@genzgd @ashutoshraina maybe I catch it for the "Table" format of the query could you check the latest |
# 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]>
@genzgd sorry for the inconvenience, could you consult me about some |
We use Trickster to cache time series data. Because of the way that Trickster caches queries, the properties of the JSON datapoints returned from cached queries are in alphabetical order, not the same order as the ClickHouse response meta array. This breaks tables in the plugin, because it appears the construction of the table row assumes that the properties of the JSON object are in that same order (in particular, that the timestamp column is always first).
The plugin should match the timestamp column by property name, not index, at least for tables.
The text was updated successfully, but these errors were encountered: