Пример
github.com/prometheus/client_model v0.6.1: go.Exemplar
Проверенный пример — golang github.com/prometheus/client_model v0.6.1: go.Exemplar. Контракт выполнен на go 1.26 · linux debian/x64 · docker и пройден.
sha256:cf9c8051062bba75beb5ed18ad6679db88a1e9dcfc1c1dde99e8cde0e63707c0
Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла.
Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди.
MIT-0
Свидетельства выполнения
Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.
- Основа свидетельства
- Подписанный контракт пройден
- Квитанции проверки
- 1
- Ключи подписи, собравшие его
- 1
Заявленная среда
linux 24 · ubuntu · glibc 2.39 x64 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.Exemplar in pkg:golang/github.com/prometheus/client_model@v0.6.1
- Символы
-
- github.com/prometheus/client_model/go.Exemplar
- Создан
- 2026-09-05T13:52:09Z
Контракт
- dto.Exemplar getter methods return default zero or nil values for nil and empty Exemplar instances.
- dto.Exemplar stores and retrieves a float64 value via GetValue.
- dto.Exemplar stores and retrieves a collection of LabelPair labels via GetLabel.
- dto.Exemplar stores and retrieves an OpenMetrics-style timestamp via GetTimestamp.
- dto.Exemplar serializes and deserializes via protobuf preserving all fields.
- dto.Exemplar.Reset clears all fields back to zero or nil values.
Файлы
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.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.Exemplar 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.Exemplar
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:139dccff95099dbeaae7ff030c5161be920e92757a4b9b31bd79da8d5f198153","contract":["dto.Exemplar getter methods return default zero or nil values for nil and empty Exemplar instances.","dto.Exemplar stores and retrieves a float64 value via GetValue.","dto.Exemplar stores and retrieves a collection of LabelPair labels via GetLabel.","dto.Exemplar stores and retrieves an OpenMetrics-style timestamp via GetTimestamp.","dto.Exemplar serializes and deserializes via protobuf preserving all fields.","dto.Exemplar.Reset clears all fields back to zero or nil values."],"goal":"verify github.com/prometheus/client_model/go.Exemplar 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.Exemplar"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"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.Exemplar"],"verifierAdapter":"golang@1"}
module example.com/exemplar
go 1.22
require (
github.com/prometheus/client_model v0.6.1
google.golang.org/protobuf v1.33.0
)
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.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
package main
import (
"fmt"
"time"
dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
func main() {
now := time.Now()
ts := timestamppb.New(now)
exemplar := &dto.Exemplar{
Label: []*dto.LabelPair{
{
Name: proto.String("trace_id"),
Value: proto.String("trace-12345"),
},
},
Value: proto.Float64(0.25),
Timestamp: ts,
}
fmt.Printf("Exemplar value: %f\n", exemplar.GetValue())
for _, l := range exemplar.GetLabel() {
fmt.Printf("Label: %s=%s\n", l.GetName(), l.GetValue())
}
if t := exemplar.GetTimestamp(); t != nil {
fmt.Printf("Timestamp: %s\n", t.AsTime().Format(time.RFC3339))
}
exemplar.Reset()
fmt.Printf("After reset, value: %f\n", exemplar.GetValue())
}
{
"schemaVersion": 1,
"goal": "verify github.com/prometheus/client_model/go.Exemplar 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.Exemplar"
]
}
package main
import (
"fmt"
"os"
"time"
dto "github.com/prometheus/client_model/go"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
func main() {
// 1. dto.Exemplar getter methods return default zero or nil values for nil and empty Exemplar instances.
var nilExemplar *dto.Exemplar
if got := nilExemplar.GetValue(); got != 0.0 {
fmt.Fprintf(os.Stderr, "nilExemplar.GetValue() expected 0, got %v\n", got)
os.Exit(1)
}
if got := nilExemplar.GetLabel(); got != nil {
fmt.Fprintf(os.Stderr, "nilExemplar.GetLabel() expected nil, got %v\n", got)
os.Exit(1)
}
if got := nilExemplar.GetTimestamp(); got != nil {
fmt.Fprintf(os.Stderr, "nilExemplar.GetTimestamp() expected nil, got %v\n", got)
os.Exit(1)
}
emptyExemplar := &dto.Exemplar{}
if got := emptyExemplar.GetValue(); got != 0.0 {
fmt.Fprintf(os.Stderr, "emptyExemplar.GetValue() expected 0, got %v\n", got)
os.Exit(1)
}
if got := emptyExemplar.GetLabel(); got != nil {
fmt.Fprintf(os.Stderr, "emptyExemplar.GetLabel() expected nil, got %v\n", got)
os.Exit(1)
}
if got := emptyExemplar.GetTimestamp(); got != nil {
fmt.Fprintf(os.Stderr, "emptyExemplar.GetTimestamp() expected nil, got %v\n", got)
os.Exit(1)
}
// 2. dto.Exemplar stores and retrieves a float64 value via GetValue.
val := 42.75
exemplarWithVal := &dto.Exemplar{
Value: proto.Float64(val),
}
if got := exemplarWithVal.GetValue(); got != val {
fmt.Fprintf(os.Stderr, "exemplarWithVal.GetValue() expected %v, got %v\n", val, got)
os.Exit(1)
}
// 3. dto.Exemplar stores and retrieves a collection of LabelPair labels via GetLabel.
labels := []*dto.LabelPair{
{
Name: proto.String("trace_id"),
Value: proto.String("req-12345"),
},
{
Name: proto.String("span_id"),
Value: proto.String("span-67890"),
},
}
exemplarWithLabels := &dto.Exemplar{
Label: labels,
}
gotLabels := exemplarWithLabels.GetLabel()
if len(gotLabels) != 2 {
fmt.Fprintf(os.Stderr, "expected 2 labels, got %d\n", len(gotLabels))
os.Exit(1)
}
if gotLabels[0].GetName() != "trace_id" || gotLabels[0].GetValue() != "req-12345" {
fmt.Fprintf(os.Stderr, "first label mismatch: %v=%v\n", gotLabels[0].GetName(), gotLabels[0].GetValue())
os.Exit(1)
}
if gotLabels[1].GetName() != "span_id" || gotLabels[1].GetValue() != "span-67890" {
fmt.Fprintf(os.Stderr, "second label mismatch: %v=%v\n", gotLabels[1].GetName(), gotLabels[1].GetValue())
os.Exit(1)
}
// 4. dto.Exemplar stores and retrieves an OpenMetrics-style timestamp via GetTimestamp.
now := time.Unix(1700000000, 500000000)
ts := timestamppb.New(now)
exemplarWithTs := &dto.Exemplar{
Timestamp: ts,
}
gotTs := exemplarWithTs.GetTimestamp()
if gotTs == nil {
fmt.Fprintf(os.Stderr, "expected non-nil timestamp\n")
os.Exit(1)
}
if gotTs.GetSeconds() != 1700000000 || gotTs.GetNanos() != 500000000 {
fmt.Fprintf(os.Stderr, "timestamp mismatch: seconds=%v nanos=%v\n", gotTs.GetSeconds(), gotTs.GetNanos())
os.Exit(1)
}
// 5. dto.Exemplar serializes and deserializes via protobuf preserving all fields.
fullExemplar := &dto.Exemplar{
Value: proto.Float64(99.5),
Label: labels,
Timestamp: ts,
}
data, err := proto.Marshal(fullExemplar)
if err != nil {
fmt.Fprintf(os.Stderr, "proto.Marshal failed: %v\n", err)
os.Exit(1)
}
decodedExemplar := &dto.Exemplar{}
if err := proto.Unmarshal(data, decodedExemplar); err != nil {
fmt.Fprintf(os.Stderr, "proto.Unmarshal failed: %v\n", err)
os.Exit(1)
}
if !proto.Equal(fullExemplar, decodedExemplar) {
fmt.Fprintf(os.Stderr, "proto.Equal failed after marshal/unmarshal\n")
os.Exit(1)
}
// 6. dto.Exemplar.Reset clears all fields back to zero or nil values.
fullExemplar.Reset()
if got := fullExemplar.GetValue(); got != 0.0 {
fmt.Fprintf(os.Stderr, "after Reset(), GetValue() expected 0, got %v\n", got)
os.Exit(1)
}
if got := fullExemplar.GetLabel(); got != nil {
fmt.Fprintf(os.Stderr, "after Reset(), GetLabel() expected nil, got %v\n", got)
os.Exit(1)
}
if got := fullExemplar.GetTimestamp(); got != nil {
fmt.Fprintf(os.Stderr, "after Reset(), GetTimestamp() expected nil, got %v\n", got)
os.Exit(1)
}
fmt.Println("All contract assertions passed.")
}
Исходный сидер
аноним