Skip to content

Instantly share code, notes, and snippets.

View kylebrandt's full-sized avatar
🦥
🛠️

Kyle Brandt kylebrandt

🦥
🛠️
View GitHub Profile
@kylebrandt
kylebrandt / time_funcs.go
Created April 1, 2025 18:33
Can't implement FunctionProvider
package sql
import (
"context"
"time"
mysql "github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"
)
@kylebrandt
kylebrandt / sql_expr_basic_usage_chatgpt.md
Created March 27, 2025 14:05
Basic Usage of SQL Expressions in Grafana

📘 Basic Usage of SQL Expressions in Grafana

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.


🔧 How SQL Expressions Work

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.

@kylebrandt
kylebrandt / README.md
Last active March 14, 2025 17:02
SQL Expressions and Full Long (Written by ChatGPT)

Why *_full_long Formats Are Essential for Handling Label Sparsity

Overview

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.


@kylebrandt
kylebrandt / func.go
Created January 26, 2025 15:55
mysql_func
package sql
import (
"fmt"
mysql "github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"
)
type SlothFunction struct{}
@kylebrandt
kylebrandt / README.md
Last active January 6, 2025 15:18
SQL Expression Input Conversion Notes

SQL Expressions and Input

  • 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"
  • 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.
@kylebrandt
kylebrandt / notes.md
Created November 7, 2024 16:20
SQL Expression Notes

SQL Expression Notes

Getting some thoughts down...

PoC Outline (with go-mysql-server)

  • Goals
    • Main Goal: go-mysql-server end-to-end inside SSE over completion for discovery, supporting some subset of cases of combining other datasources
    • Run go-mysql-server without "server"
  • Use SDK for response
@kylebrandt
kylebrandt / README.md
Last active November 21, 2024 15:29
Recorded Query Multi-Dimensions - Dataplane + SSE

Recorded Queries and Multiple Dimensions, The Ugly Details

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.
@kylebrandt
kylebrandt / README.md
Last active June 7, 2024 12:55
ScopeNodes Example

Notes

  • 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.

Files

  • example.http: VSCode REST Client Extension HTTP Calls
  • scopesnodes.json: JSON output of ScopeNode kind items created in example.http
  • scopes.json: JSON output of Scope kind items created in example.http
  • find_no_param_response.json and find_parent_param_is_applications_response.json: The responses to the two calls to the find/scope_node_children endpoint that are in the example.http file
@kylebrandt
kylebrandt / README.md
Last active June 6, 2024 14:11
ScopeDashboardBinding Summary and Examples

Scopes API Summary

We have created an alpha version of the API for scopes and scope/dashboard relationships. This is an OpenAPI and kubernetes style API.

Object Summary

There are two main objects (kinds):

  • Scope: Each Scope's spec includes an array of ScopeFilter and the string properties title and description.
  • ScopeFilter has key, operator (enum), and value
@kylebrandt
kylebrandt / peakq.http
Last active February 6, 2024 14:20
peakq http
### Render a Basic template with POST
POST http://admin:admin@localhost:3000/apis/peakq.grafana.app/v0alpha1/render?var-metricName=up
Content-Type: application/json
Accept: application/json
{
"title": "Test",
"vars": [
{
"key": "metricName",