Пример
github.com/prometheus/client_model v0.6.1: go.Metric
Проверенный пример — golang github.com/prometheus/client_model v0.6.1: go.Metric. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:70fe550e51f669b2bc8ecde054f3dfcd4d77132710c1e45a78b65c44b4bef1a3
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
go linux 24 · ubuntu · glibc 2.39 x64 go go go
Среды запусков проверки
| Окружение | Контракт | Этапы | Запуск |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-05 |
Кейс
HOW- Цель
- verify github.com/prometheus/client_model/go.Metric in pkg:golang/github.com/prometheus/client_model@v0.6.1
- Символы
-
- github.com/prometheus/client_model/go.Metric
- Окружение
- go
- Создан
- 2026-09-05T10:30:58Z
Контракт
- dto.Metric getter methods (GetLabel, GetGauge, GetCounter, GetSummary, GetUntyped, GetHistogram, GetTimestampMs) return nil or zero for nil and empty instances.
- dto.Metric stores and retrieves labels, gauge metric value, and timestamp in milliseconds.
- dto.Metric stores and retrieves counter metric value.
- dto.Metric.Reset clears all fields back to zero values.
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract_test.go
Исходный код
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify github.com/prometheus/client_model/go.Metric in pkg:golang/github.com/prometheus/client_model@v0.6.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/prometheus/client_model@v0.6.1
Demonstrate these symbols/APIs:
- github.com/prometheus/client_model/go.Metric
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:aea026c1bb42221c894415996ca6398176257eda48b8c0420a4e5e14d5c0b51d","contract":["dto.Metric getter methods (GetLabel, GetGauge, GetCounter, GetSummary, GetUntyped, GetHistogram, GetTimestampMs) return nil or zero for nil and empty instances.","dto.Metric stores and retrieves labels, gauge metric value, and timestamp in milliseconds.","dto.Metric stores and retrieves counter metric value.","dto.Metric.Reset clears all fields back to zero values."],"goal":"verify github.com/prometheus/client_model/go.Metric in pkg:golang/github.com/prometheus/client_model@v0.6.1","kind":"HOW","packages":["pkg:golang/github.com/prometheus/client_model@v0.6.1"],"schemaVersion":1,"symbols":["github.com/prometheus/client_model/go.Metric"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","executionContext":"go","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/prometheus/client_model@v0.6.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/prometheus/client_model@v0.6.1","symbols":["github.com/prometheus/client_model/go.Metric"],"verifierAdapter":"golang@1"}
module example.com/metric
go 1.22
require (
github.com/prometheus/client_model v0.6.1
google.golang.org/protobuf v1.34.2
)
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
package main
import (
"fmt"
dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
)
func main() {
labelName := "method"
labelVal := "GET"
gaugeVal := 123.45
tsMs := int64(1700000000000)
metric := &dto.Metric{
Label: []*dto.LabelPair{
{
Name: proto.String(labelName),
Value: proto.String(labelVal),
},
},
Gauge: &dto.Gauge{
Value: proto.Float64(gaugeVal),
},
TimestampMs: proto.Int64(tsMs),
}
fmt.Printf("Metric label count: %d\n", len(metric.GetLabel()))
if len(metric.GetLabel()) > 0 {
fmt.Printf("Metric label: %s=%s\n", metric.GetLabel()[0].GetName(), metric.GetLabel()[0].GetValue())
}
if g := metric.GetGauge(); g != nil {
fmt.Printf("Metric gauge value: %f\n", g.GetValue())
}
fmt.Printf("Metric timestamp ms: %d\n", metric.GetTimestampMs())
metric.Reset()
fmt.Printf("After reset, labels count: %d\n", len(metric.GetLabel()))
}
{
"schemaVersion": 1,
"goal": "verify github.com/prometheus/client_model/go.Metric in pkg:golang/github.com/prometheus/client_model@v0.6.1",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/prometheus/client_model@v0.6.1"
],
"symbols": [
"github.com/prometheus/client_model/go.Metric"
]
}
package test
import (
"testing"
dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
)
func TestMetricNilAndDefaults(t *testing.T) {
var nilMetric *dto.Metric
if got := nilMetric.GetLabel(); got != nil {
t.Errorf("nilMetric.GetLabel() = %v, want nil", got)
}
if got := nilMetric.GetGauge(); got != nil {
t.Errorf("nilMetric.GetGauge() = %v, want nil", got)
}
if got := nilMetric.GetCounter(); got != nil {
t.Errorf("nilMetric.GetCounter() = %v, want nil", got)
}
if got := nilMetric.GetSummary(); got != nil {
t.Errorf("nilMetric.GetSummary() = %v, want nil", got)
}
if got := nilMetric.GetUntyped(); got != nil {
t.Errorf("nilMetric.GetUntyped() = %v, want nil", got)
}
if got := nilMetric.GetHistogram(); got != nil {
t.Errorf("nilMetric.GetHistogram() = %v, want nil", got)
}
if got := nilMetric.GetTimestampMs(); got != 0 {
t.Errorf("nilMetric.GetTimestampMs() = %v, want 0", got)
}
emptyMetric := &dto.Metric{}
if got := emptyMetric.GetLabel(); got != nil {
t.Errorf("emptyMetric.GetLabel() = %v, want nil", got)
}
if got := emptyMetric.GetGauge(); got != nil {
t.Errorf("emptyMetric.GetGauge() = %v, want nil", got)
}
if got := emptyMetric.GetTimestampMs(); got != 0 {
t.Errorf("emptyMetric.GetTimestampMs() = %v, want 0", got)
}
}
func TestMetricWithLabelsAndGauge(t *testing.T) {
labelName := "handler"
labelVal := "prometheus"
gaugeVal := 99.5
ts := int64(1690000000123)
metric := &dto.Metric{
Label: []*dto.LabelPair{
{
Name: proto.String(labelName),
Value: proto.String(labelVal),
},
},
Gauge: &dto.Gauge{
Value: proto.Float64(gaugeVal),
},
TimestampMs: proto.Int64(ts),
}
labels := metric.GetLabel()
if len(labels) != 1 {
t.Fatalf("len(metric.GetLabel()) = %d, want 1", len(labels))
}
if labels[0].GetName() != labelName || labels[0].GetValue() != labelVal {
t.Errorf("label mismatch: got name=%s val=%s, want name=%s val=%s",
labels[0].GetName(), labels[0].GetValue(), labelName, labelVal)
}
gauge := metric.GetGauge()
if gauge == nil {
t.Fatal("metric.GetGauge() returned nil")
}
if gauge.GetValue() != gaugeVal {
t.Errorf("gauge.GetValue() = %v, want %v", gauge.GetValue(), gaugeVal)
}
if metric.GetTimestampMs() != ts {
t.Errorf("metric.GetTimestampMs() = %v, want %v", metric.GetTimestampMs(), ts)
}
}
func TestMetricWithCounter(t *testing.T) {
counterVal := 1500.0
metric := &dto.Metric{
Counter: &dto.Counter{
Value: proto.Float64(counterVal),
},
}
counter := metric.GetCounter()
if counter == nil {
t.Fatal("metric.GetCounter() returned nil")
}
if counter.GetValue() != counterVal {
t.Errorf("counter.GetValue() = %v, want %v", counter.GetValue(), counterVal)
}
}
func TestMetricReset(t *testing.T) {
metric := &dto.Metric{
Label: []*dto.LabelPair{
{
Name: proto.String("service"),
Value: proto.String("web"),
},
},
Gauge: &dto.Gauge{
Value: proto.Float64(10.0),
},
TimestampMs: proto.Int64(123456789),
}
metric.Reset()
if got := metric.GetLabel(); got != nil {
t.Errorf("after Reset(), metric.GetLabel() = %v, want nil", got)
}
if got := metric.GetGauge(); got != nil {
t.Errorf("after Reset(), metric.GetGauge() = %v, want nil", got)
}
if got := metric.GetTimestampMs(); got != 0 {
t.Errorf("after Reset(), metric.GetTimestampMs() = %v, want 0", got)
}
}
Исходный сидер
аноним