Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

クローズ
#853 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
go
領域
api

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
TypeScript
スター
33
フォーク
88
平均マージ
1日 17時間
マージ済み PR(30日)
37

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

perses/plugins のほかの issue

perses/plugins の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。