Calculate percentage of syn packages against total packets, per direction
package sql | |
import ( | |
"context" | |
"time" | |
mysql "github.com/dolthub/go-mysql-server/sql" | |
"github.com/dolthub/go-mysql-server/sql/types" | |
) |
SQL expressions in Grafana let you perform lightweight SQL-like transformations on the results of other queries — directly within the panel. This is great for reshaping, renaming, filtering, and aggregating data without modifying the original datasource query.
SQL expressions operate on the output of another query in the same panel, referenced by its query letter (e.g., A
, B
). These expressions are parsed and executed by Grafana — not sent to an external database.
In Grafana, data coming from many sources includes sparse labels — meaning some series have label keys that others do not.
This is common in systems like Prometheus, OpenTelemetry, or SQL queries with GROUP BY.
However, traditional long formats (like time_series_long
or numeric_long
) do not preserve label sparsity correctly, leading to broken behaviors in visualization, alerts, and expressions.
package sql | |
import ( | |
"fmt" | |
mysql "github.com/dolthub/go-mysql-server/sql" | |
"github.com/dolthub/go-mysql-server/sql/types" | |
) | |
type SlothFunction struct{} |
- What do we want to happen to data when read by SQL Expressions?
- Data from an individual query needs to appear as a single table
- Raw table data maps directly to single table
- The "Long" formats of the TimeSeries and Numeric kinds map directly to a table
- The "Multi" and "wide" formats of the TimeSeries and Numeric kinds need conversion to the kind's "Long" format
- For now I'm calling this "SQL Conversion Rules"
- Data from an individual query needs to appear as a single table
- What does SSE currently do for conversion?
- To generalize, SSE reads TimeSeries and Numeric data in different formats, and converts them to the multi format for their kind. Things like alerting depend on this behavior.
Docs (https://grafana.com/docs/grafana/latest/administration/recorded-queries/#how-recorded-queries-work):
Recorded queries only work with backend data source plugins. Refer to Backend data source plugin for more information about backend data source plugins. You can recorded four types of queries:
- single row and column - A query that returns a single row and column.
- row count - A query that returns meaningful rows to be counted.
- expression - Any expression. To learn more about creating and using expressions, see Write expression queries.
- dataplane numeric - A query that returns dataplane numeric kind data.
- NB" The "name" (id) fields are named using the path in these examples. This is not part of the API itself currently
- e.g.
http://localhost:3000/swagger?urls.primaryName=scope.grafana.app%2Fv0alpha1
for Swagger definitions.
example.http
: VSCode REST Client Extension HTTP Callsscopesnodes.json
: JSON output ofScopeNode
kind items created inexample.http
scopes.json
: JSON output ofScope
kind items created inexample.http
find_no_param_response.json
andfind_parent_param_is_applications_response.json
: The responses to the two calls to thefind/scope_node_children
endpoint that are in theexample.http
file
We have created an alpha version of the API for scopes and scope/dashboard relationships. This is an OpenAPI and kubernetes style API.
There are two main objects (kinds):
Scope
: Each Scope's spec includes an array ofScopeFilter
and the string propertiestitle
anddescription
.ScopeFilter
haskey
,operator
(enum), andvalue