샘플
github.com/prometheus/client_model v0.5.0: go.MetricType_HISTOGRAM
검증된 샘플 — golang github.com/prometheus/client_model v0.5.0: go.MetricType_HISTOGRAM. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다.
sha256:897cced3669107edfc8962b46f5894dc5a7f7c487cb660a53cd14507b8d3eab1
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 1
선언된 환경
go 1.26 linux 24 · ubuntu · glibc 2.39 amd64 go 1.26 go 1.26 go 1
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-26 |
| 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-07 |
케이스
HOW- 목표
- verify github.com/prometheus/client_model/go.MetricType_HISTOGRAM in pkg:golang/github.com/prometheus/client_model@v0.5.0
- 심벌
-
- github.com/prometheus/client_model/go.MetricType_HISTOGRAM
- 환경
- go 1.26.6
- 생성일
- 2026-08-26T12:10:18Z
컨트랙트
- NewHistogramMetricFamily creates a MetricFamily with MetricType_HISTOGRAM, non-nil Histogram, and specified labels, sample count, sample sum, and buckets
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- histogram.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.MetricType_HISTOGRAM in pkg:golang/github.com/prometheus/client_model@v0.5.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/prometheus/client_model@v0.5.0
Demonstrate these symbols/APIs:
- github.com/prometheus/client_model/go.MetricType_HISTOGRAM
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:49180ef4ef4e4d7a4306d91b34dc1cf38e7c7e46f97f451ddfd4a415523f7de8","contract":["NewHistogramMetricFamily creates a MetricFamily with MetricType_HISTOGRAM, non-nil Histogram, and specified labels, sample count, sample sum, and buckets"],"goal":"verify github.com/prometheus/client_model/go.MetricType_HISTOGRAM in pkg:golang/github.com/prometheus/client_model@v0.5.0","kind":"HOW","packages":["pkg:golang/github.com/prometheus/client_model@v0.5.0"],"schemaVersion":1,"symbols":["github.com/prometheus/client_model/go.MetricType_HISTOGRAM"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/github.com/prometheus/client_model@v0.5.0"],"schemaVersion":1,"subject":"pkg:golang/github.com/prometheus/client_model@v0.5.0","symbols":["github.com/prometheus/client_model/go.MetricType_HISTOGRAM"],"verifierAdapter":"golang@1"}
module sample
go 1.22
require github.com/prometheus/client_model v0.5.0
require google.golang.org/protobuf v1.33.0 // indirect
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.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
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 sample
import (
dto "github.com/prometheus/client_model/go"
)
// BucketConfig holds the upper bound and cumulative count for a histogram bucket.
type BucketConfig struct {
UpperBound float64
CumulativeCount uint64
}
// StringPtr returns a pointer to the given string.
func StringPtr(s string) *string {
return &s
}
// Float64Ptr returns a pointer to the given float64.
func Float64Ptr(f float64) *float64 {
return &f
}
// Uint64Ptr returns a pointer to the given uint64.
func Uint64Ptr(u uint64) *uint64 {
return &u
}
// MetricTypePtr returns a pointer to the given MetricType.
func MetricTypePtr(t dto.MetricType) *dto.MetricType {
return &t
}
// NewHistogramMetricFamily creates a MetricFamily with MetricType_HISTOGRAM, containing a histogram metric with specified labels, counts, and buckets.
func NewHistogramMetricFamily(name, help string, labels map[string]string, sampleCount uint64, sampleSum float64, buckets []BucketConfig) *dto.MetricFamily {
var labelPairs []*dto.LabelPair
for k, v := range labels {
labelPairs = append(labelPairs, &dto.LabelPair{
Name: StringPtr(k),
Value: StringPtr(v),
})
}
var dtoBuckets []*dto.Bucket
for _, b := range buckets {
dtoBuckets = append(dtoBuckets, &dto.Bucket{
UpperBound: Float64Ptr(b.UpperBound),
CumulativeCount: Uint64Ptr(b.CumulativeCount),
})
}
return &dto.MetricFamily{
Name: StringPtr(name),
Help: StringPtr(help),
Type: MetricTypePtr(dto.MetricType_HISTOGRAM),
Metric: []*dto.Metric{
{
Label: labelPairs,
Histogram: &dto.Histogram{
SampleCount: Uint64Ptr(sampleCount),
SampleSum: Float64Ptr(sampleSum),
Bucket: dtoBuckets,
},
},
},
}
}
{
"schemaVersion": 1,
"goal": "verify github.com/prometheus/client_model/go.MetricType_HISTOGRAM in pkg:golang/github.com/prometheus/client_model@v0.5.0",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/prometheus/client_model@v0.5.0"
],
"symbols": [
"github.com/prometheus/client_model/go.MetricType_HISTOGRAM"
]
}
package test
import (
"testing"
dto "github.com/prometheus/client_model/go"
"sample"
)
func TestHistogramMetricFamilyContract(t *testing.T) {
name := "http_request_duration_seconds"
help := "Histogram of request duration in seconds"
labels := map[string]string{
"handler": "api_v1_users",
"method": "GET",
}
sampleCount := uint64(100)
sampleSum := 25.4
buckets := []sample.BucketConfig{
{UpperBound: 0.05, CumulativeCount: 20},
{UpperBound: 0.1, CumulativeCount: 55},
{UpperBound: 0.25, CumulativeCount: 85},
{UpperBound: 0.5, CumulativeCount: 98},
{UpperBound: 1.0, CumulativeCount: 100},
}
mf := sample.NewHistogramMetricFamily(name, help, labels, sampleCount, sampleSum, buckets)
if mf.GetName() != name {
t.Fatalf("expected metric family name %q, got %q", name, mf.GetName())
}
if mf.GetHelp() != help {
t.Fatalf("expected metric family help %q, got %q", help, mf.GetHelp())
}
if mf.GetType() != dto.MetricType_HISTOGRAM {
t.Fatalf("expected metric family type %v (HISTOGRAM), got %v", dto.MetricType_HISTOGRAM, mf.GetType())
}
if mf.GetType().String() != "HISTOGRAM" {
t.Fatalf("expected type string 'HISTOGRAM', got %q", mf.GetType().String())
}
metrics := mf.GetMetric()
if len(metrics) != 1 {
t.Fatalf("expected 1 metric, got %d", len(metrics))
}
m := metrics[0]
hist := m.GetHistogram()
if hist == nil {
t.Fatal("expected Histogram metric to be non-nil")
}
if hist.GetSampleCount() != sampleCount {
t.Fatalf("expected sample count %d, got %d", sampleCount, hist.GetSampleCount())
}
if hist.GetSampleSum() != sampleSum {
t.Fatalf("expected sample sum %f, got %f", sampleSum, hist.GetSampleSum())
}
histBuckets := hist.GetBucket()
if len(histBuckets) != len(buckets) {
t.Fatalf("expected %d buckets, got %d", len(buckets), len(histBuckets))
}
for i, b := range histBuckets {
if b.GetUpperBound() != buckets[i].UpperBound {
t.Fatalf("bucket[%d]: expected upper bound %f, got %f", i, buckets[i].UpperBound, b.GetUpperBound())
}
if b.GetCumulativeCount() != buckets[i].CumulativeCount {
t.Fatalf("bucket[%d]: expected cumulative count %d, got %d", i, buckets[i].CumulativeCount, b.GetCumulativeCount())
}
}
labelPairs := m.GetLabel()
if len(labelPairs) != len(labels) {
t.Fatalf("expected %d label pairs, got %d", len(labels), len(labelPairs))
}
foundLabels := make(map[string]string)
for _, lp := range labelPairs {
foundLabels[lp.GetName()] = lp.GetValue()
}
for k, expectedVal := range labels {
if foundVal, ok := foundLabels[k]; !ok || foundVal != expectedVal {
t.Fatalf("expected label %s=%s, got %s=%s", k, expectedVal, k, foundVal)
}
}
}
오리진 시더
익명