Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa
#853 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
TypeScript
Stelle
33
Fork
88
Merge medio
2g 43m
PR unite (30g)
34

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di perses/plugins

Tutte le issue di perses/plugins

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.