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

for Table pluggin, fields that are not Integer are typed as string #199

Closed
Stephane-Thales opened this issue Jun 18, 2020 · 12 comments · Fixed by #210
Closed

for Table pluggin, fields that are not Integer are typed as string #199

Stephane-Thales opened this issue Jun 18, 2020 · 12 comments · Fixed by #210
Assignees

Comments

@Stephane-Thales
Copy link

Hi all,

Only for the Table plugin (so far it work with the Stat object)
With a query format as Table (not Time series)

If a clickhouse Field is Nullable(Float64), Float64, Decimal ... it's typed as String.
So the plugin can't be configured to apply numeric related formatting (%, Threshold ...)

To check, compare types between

  • Query inspector / Query / Object / Response / Meta / Object / type
  • Query inspector / JSON / Dataframe structure / Array[1] / 0:Object / fields: / 0:Object

Workaround is to apply in the query a
toInt16(ifNull( MyField ,0)) as MyField
But that prevent to display decimals.

Is that a Table plugin issue or a clickhouse-grafana plugin issue ?
Can that be fixed in clickhouse-grafana plugin ?

thanks

@Slach
Copy link
Collaborator

Slach commented Jun 25, 2020

Dear @Stephane-Thales, could you help me reproduce issue?

I tried to reproduce with following steps:

git checkout https://github.com/Vertamedia/clickhouse-grafana
cd clickhouse-grafana
git checkout master
docker-compose up -d grafana
docker-compose exec clickhouse clickhouse-client -mn

run following queries inside clickhouse-client

DROP TABLE IF EXISTS default.test_grafana;
CREATE TABLE IF NOT EXISTS default.test_grafana(event_time DateTime, service_name LowCardinality(String), too_big_value Float64)
ENGINE=MergeTree()
    PARTITION BY toYYYYMM(event_time)
    ORDER BY (event_time, service_name);

INSERT INTO default.test_grafana(event_time, service_name, too_big_value) SELECT toDateTime(now()-(number*10)) AS event_time, if(rand() % 2 = 1,'mysql','postgresql') AS service_name, 1000000000.05 AS too_big_value FROM numbers(1000);
INSERT INTO default.test_grafana(event_time, service_name, too_big_value) SELECT toDateTime(now()+(number*10)) AS event_time, 'mysql' AS service_name, 1000000000.05 AS too_big_value FROM numbers(1000);
INSERT INTO default.test_grafana(event_time, service_name, too_big_value) SELECT toDateTime(now()+((500+number)*10)) AS event_time, 'postgresql' AS service_name, 1000000000.05 AS too_big_value FROM numbers(1000);
\q;

open grafana at http://localhost:3000/dashboard/new and add the following query:

SELECT sum(too_big_value) AS v, service_name FROM $table WHERE $timeFilter
GROUP BY service_name
ORDER BY v DESC

and got the following results:
image

@Stephane-Thales
Copy link
Author

Hi @Slach ,

for reference, i'm using

Grafana v7.0.3 (00ee734baf)
clickhouse server 20.4.3.16
pluggin	ClickHouse datasource for Grafana 4.6+   1.9.5

to reproduce my issue I've used the same table than you :

DROP TABLE IF EXISTS default.test_grafana;
CREATE TABLE IF NOT EXISTS default.test_grafana(event_time DateTime, service_name LowCardinality(String), too_big_value Float64)
ENGINE=MergeTree()
    PARTITION BY toYYYYMM(event_time)
    ORDER BY (event_time, service_name);

INSERT INTO default.test_grafana(event_time, service_name, too_big_value) SELECT toDateTime(now()-(number*10)) AS event_time, if(rand() % 2 = 1,'mysql','postgresql') AS service_name, 1000000000.05 AS too_big_value FROM numbers(1000);
INSERT INTO default.test_grafana(event_time, service_name, too_big_value) SELECT toDateTime(now()+(number*10)) AS event_time, 'mysql' AS service_name, 1000000000.05 AS too_big_value FROM numbers(1000);
INSERT INTO default.test_grafana(event_time, service_name, too_big_value) SELECT toDateTime(now()+((500+number)*10)) AS event_time, 'postgresql' AS service_name, 1000000000.05 AS too_big_value FROM numbers(1000);

select count(*) from default.test_grafana;
-- 3000

select * from default.test_grafana order by event_time, service_name ;
/*
event_time			service_name	too_big_value
2020-06-26 06:10:41	postgresql		1000000000.05
2020-06-26 06:10:51	postgresql		1000000000.05
2020-06-26 06:11:01	mysql			1000000000.05
2020-06-26 06:11:11	mysql			1000000000.05 
 */

then New dashboard, new pannel
first query like yours

SELECT sum(too_big_value) AS v, service_name FROM $table WHERE $timeFilter
GROUP BY service_name
ORDER BY v DESC

in clickhouse 👍

SELECT sum(too_big_value) AS v, service_name FROM default.test_grafana WHERE event_time >= toDateTime(1593111854) GROUP BY service_name ORDER BY v DESC;
/*
1522000000076.1428	mysql
1478000000073.9407	postgresql
 */	

grafana bug field type 001

Note the change of option "Cell display mode" to "Color text" for visualisation of the text vs number.

grafana bug field type 002

The data is well provided as float by clickhouse, with the decimals

grafana bug field type 003

But Grafana think it's string

If I change the query to that :

SELECT toInt64(sum(too_big_value)) AS v, service_name FROM $table WHERE $timeFilter
GROUP BY service_name
ORDER BY v DESC

Then the fiel is recognized as a number (color coding is applied):

grafana bug field type 004

Thanks.

@Slach
Copy link
Collaborator

Slach commented Jun 28, 2020

I catch it
image

please use latest master branch or wait when 2.0.2 will be released on grafana-plugin-repository

Slach added a commit that referenced this issue Jun 28, 2020
fix #199
also partial solution for #169, 
array variables need investigation on Grafana Core
@mzealey
Copy link

mzealey commented Jun 29, 2020

I have pulled the latest master but this is not fixed for me

SELECT
    splitByChar('.', Path)[3] Server,
    splitByChar('.', Path)[5] User,
    avg(Average) Average,
    max(Maximum) Maximum
FROM cloudlinux_faults
WHERE (Date BETWEEN toDate($from) AND toDate($to))
GROUP BY Path
ORDER BY Average DESC
LIMIT $total

still thinks these Float64-based cols are strings.

@Slach Slach reopened this Jun 29, 2020
@Slach
Copy link
Collaborator

Slach commented Jun 29, 2020

@mzealey could you share SHOW CREATE TABLE cloudlinux_faults?
did you try to redefine decimals character in Average or Maximum columns?
Which Grafana version do you use?

@mzealey
Copy link

mzealey commented Jun 29, 2020

CREATE TABLE IF NOT EXISTS cloudlinux_faults (
  Date Date,
  Path String,
  Average Float64,
  Maximum Float64
) ENGINE = MergeTree()
PARTITION BY toYYYYMM(Date)
ORDER BY (Date, Path);

@mzealey
Copy link

mzealey commented Jun 29, 2020

latest grafana docker image so 7-series

@Slach
Copy link
Collaborator

Slach commented Jun 29, 2020

did you try to redefine decimals in "Field" tab for in Average and Maximum columns?

@mzealey
Copy link

mzealey commented Jun 29, 2020

I am not sure what you mean by this?

@Slach
Copy link
Collaborator

Slach commented Jun 29, 2020

I mean Decimals on "Fields" tab on right side in panel edit
image

@mzealey
Copy link

mzealey commented Jun 29, 2020

Ah yes then they work as numbers. Is there no way to do this automatically in the plugin ?

@Slach
Copy link
Collaborator

Slach commented Jun 29, 2020

look like it's a not a plugin scope
please look at 94ebf76#diff-dd6ae047951d2bef1b8eec9a65765b4eR175
plugin already convert ClickHouse numeric related types to JavaScript "number"
after that visualization plugins continue to convert it to visual representations

@Slach Slach closed this as completed Jun 29, 2020
Slach added a commit to Altinity/grafana-plugin-repository that referenced this issue Jul 7, 2020
# 2.0.2 (2020-07-07)

## Enhancements:
* add alerts support for Windows and MacOSX
* improve ad-hoc filters for query field values as `SELECT DISTINCT field AS value FROM db.table LIMIT 300`, Altinity/clickhouse-grafana#222
* add the ability to multiple JOIN parsing Altinity/clickhouse-grafana#206
* multiple improvements for docker-compose environments, add automatic dashboards and data source provisions which help to reproduce most of the corner cases which happens in Grafana + ClickHouse

## Fixes:
* apply a workaround for UTC timezone for Date and DateTime columns in grafana dashboards Altinity/clickhouse-grafana#117
* clear documentation about timestamp term for $from and $to Altinity/clickhouse-grafana#115
* fix AST parsing corner case in `WHERE [test, 'test']` "," was skipped, fix ah-doc AST FROM recursive parsing Altinity/clickhouse-grafana#99
* fix corner cases for table functions parsing when Adhoc filter applied Altinity/clickhouse-grafana#130
* fix multiple grammar issues in README.md
* fix convert rules for Float, Decimal columns from Clickhouse to Grafana Table plugin Altinity/clickhouse-grafana#199
* fix corner cases when Grafana Template variable value represented as an array of strings Altinity/clickhouse-grafana#169
* fix AST parsing corner cases for $macroFunctions correct position for FROM statement Altinity/clickhouse-grafana#187

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
Development

Successfully merging a pull request may close this issue.

3 participants