Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Go SDK: labelvalues.Datasource("$var") emits typed struct instead of raw variable reference, breaking variable queries

Cerrado
#853 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
68/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go
Área
api

Línea de trabajo

Start at labelvalues.Datasource and promDatasource.Selector in the Go SDK datasource package, then compare the emitted JSON with the raw-string representation confirmed by PR #775. Reproduce the PrometheusLabelValues example and trace how the selector is marshaled. Done means datasource variable references serialize as a bare "$datasource" string while typed datasource selectors remain supported.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Description

When building Perses dashboards programmatically with the Go SDK, calling labelvalues.Datasource("$datasource") to bind a PrometheusLabelValuesVariable to the selected datasource variable produces output that silently breaks all variable queries.

What the SDK emits (wrong)

"datasource": {
  "kind": "PrometheusDatasource",
  "name": "$datasource"
}

What Perses requires for a variable reference (correct)

"datasource": "$datasource"

PR #775 already confirmed this is the correct representation for datasource variable references. The CUE schema for spec.datasource is a disjunction that allows either a raw $variable string or a typed struct — but only the raw string triggers variable substitution at runtime.

Consequence

When the typed struct form is used with a variable name, Perses resolves it as a literal datasource name lookup. Since no registered datasource is named "$datasource", every label-values variable query returns no data — silently, with no visible error in the dashboard.

Steps to reproduce

labelvalues.PrometheusLabelValues("region",
    labelvalues.Datasource("$datasource"),
    labelvalues.Matchers("my_metric"),
)

Produces:

{
  "kind": "PrometheusLabelValuesVariable",
  "spec": {
    "datasource": { "kind": "PrometheusDatasource", "name": "$datasource" },
    "labelName": "region",
    "matchers": ["my_metric"]
  }
}

All region variable queries return no data.

Root cause

labelvalues.Datasource(name) calls promDatasource.Selector(name) which returns &datasource.Selector{Kind: PluginKind, Name: name}. This struct always serializes as the typed object form — there is no code path in the SDK to emit a bare "$variable" string.

Suggested fix

One of:

  1. In github.com/perses/perses/go-sdk/datasource, add a custom MarshalJSON to Selector that emits a plain string when Name matches ^\$\w+$ and Kind is empty.
  2. Add a new option labelvalues.DatasourceVariable(variableName string) in this package that sets spec.datasource to the raw string "$variableName" instead of constructing a Selector struct.

Related

  • perses/plugins#775 — confirmed the typed struct is wrong for variable references (migration fix)
  • perses/perses#3407 — runtime failure when using a datasource variable in variable plugin specs
Lenguaje dominante
TypeScript
Estrellas
33
Forks
91
Merge medio
1 d 17 h
PR fusionados (30 d)
37

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de perses/plugins

Todos los issues de perses/plugins

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.