grafana-druid-plugin / druidplugin

This repository contains the druid plugin for Grafana 3.0
Apache License 2.0
101 stars 83 forks source link

Not able to submit `datasource` of type `query` to the plugin. #125

Closed saketbairoliya2 closed 1 year ago

saketbairoliya2 commented 1 year ago

I've a druid query like this:

{
    "queryType": "scan",
    "context": {
        "queryId": "05fc0083-e038-4b76-9b7d-615fb5eb8029"
    },
    "intervals": {
        "type": "intervals",
        "intervals": [
            "1970-01-01T00:00:00Z/2030-01-01T00:00:00Z"
        ]
    },
    "legacy": true,
    "columns": [
        "timestamp",
        "631b7586-7993-4619-8193-eb5bfa816dc1",
        "aa8986b3-6153-4aa8-b9b4-82bde592a3b6",
        "3e7c6ca2-faba-4072-b269-57a5370bc17f"
    ],
    "dataSource": {
        "type": "query",
        "query": {
            "dataSource": {
                "type": "table",
                "name": "multi_tenant_join_pred_label_regression"
            },
            "dimensions": [{
                "type": "default",
                "dimension": "__model_id__",
                "outputType": "STRING"
            }],
            "intervals": {
                "type": "intervals",
                "intervals": [
                    "2022-01-12T10:59:51Z/2024-06-29T10:59:51Z"
                ]
            },
            "aggregations": [{
                    "type": "doubleSum",
                    "fieldName": "sum_difference_squares_label_pred",
                    "name": "sum"
                },
                {
                    "type": "doubleSum",
                    "fieldName": "count",
                    "name": "count"
                }
            ],
            "postAggregations": [{
                    "type": "arithmetic",
                    "name": "MSE",
                    "fn": "/",
                    "fields": [{
                            "type": "fieldAccess",
                            "fieldName": "sum"
                        },
                        {
                            "type": "fieldAccess",
                            "fieldName": "count"
                        }
                    ]
                },
                {
                    "type": "expression",
                    "name": "RMSE",
                    "expression": "sqrt(MSE)"
                },
                {
                    "type": "expression",
                    "name": "631b7586-7993-4619-8193-eb5bfa816dc1",
                    "expression": "case_searched((\"__model_id__\" == '631b7586-7993-4619-8193-eb5bfa816dc1'), RMSE, 0)"
                },
                {
                    "type": "expression",
                    "name": "aa8986b3-6153-4aa8-b9b4-82bde592a3b6",
                    "expression": "case_searched((\"__model_id__\" == 'aa8986b3-6153-4aa8-b9b4-82bde592a3b6'), RMSE, 0)"
                },
                {
                    "type": "expression",
                    "name": "3e7c6ca2-faba-4072-b269-57a5370bc17f",
                    "expression": "case_searched((\"__model_id__\" == '3e7c6ca2-faba-4072-b269-57a5370bc17f'), RMSE, 0)"
                }
            ],
            "filter": {
                "type": "and",
                "fields": [{
                    "type": "and",
                    "fields": [{
                            "type": "selector",
                            "dimension": "__tenant_id__",
                            "value": "on-prem"
                        },
                        {
                            "type": "or",
                            "fields": [{
                                    "type": "and",
                                    "fields": [{
                                            "type": "selector",
                                            "dimension": "__model_id__",
                                            "value": "668fd344-fa26-4c4c-a90b-562cc12fd509"
                                        },
                                        {
                                            "type": "selector",
                                            "dimension": "__split_id__",
                                            "value": "782d67c8-2df6-4cbf-a2ff-23b0f3adf71a"
                                        }
                                    ]
                                },
                                {
                                    "type": "and",
                                    "fields": [{
                                            "type": "selector",
                                            "dimension": "__model_id__",
                                            "value": "aa8986b3-6153-4aa8-b9b4-82bde592a3b6"
                                        },
                                        {
                                            "type": "selector",
                                            "dimension": "__split_id__",
                                            "value": "12473d19-64fc-44b6-92b8-3c8620593083"
                                        }
                                    ]
                                },
                                {
                                    "type": "and",
                                    "fields": [{
                                            "type": "selector",
                                            "dimension": "__model_id__",
                                            "value": "3e7c6ca2-faba-4072-b269-57a5370bc17f"
                                        },
                                        {
                                            "type": "selector",
                                            "dimension": "__split_id__",
                                            "value": "5eb9341f-2d1f-416d-9b1a-ba6ac7ed7e9d"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }]
            },
            "queryType": "groupBy",
            "granularity": "day"
        }
    }
}

This works in druid:

Screenshot 2023-07-04 at 3 03 29 PM

But when I try the same query in the Plugin, I get error:

            "error": "POST http://localhost:8585/druid/v2 giving up after 1 attempt(s): failed to query Druid: {Error:Unknown exception ErrorMessage:Cannot construct instance of `org.apache.druid.query.QueryDataSource`, problem: 'query' must be nonnull\n at [Source: (org.eclipse.jetty.server.HttpInputOverHTTP); line: 1, column: 2101] (through reference chain: org.apache.druid.query.scan.ScanQuery[\"dataSource\"]) ErrorClass:com.fasterxml.jackson.databind.exc.ValueInstantiationException Host:}",

Screenshot 2023-07-04 at 3 06 40 PM

I see that the UI on Grafana is able to understand the query but backend seems to through the error. What is wrong here? Can someone suggest?