CodeSampleX

Sample

github.com/prometheus/client_golang v1.19.1: prometheus.NewGauge

Verified sample for golang github.com/prometheus/client_golang v1.19.1: prometheus.NewGauge. The contract ran on go 1.26 · linux alpine/x64 · docker and…

sha256:268cb40bf3d72831d7458b74dd31ac0e3328bc5476f3124cbc98c15109a0b2d8

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
2
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
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

Case

HOW
Goal
verify github.com/prometheus/client_golang/prometheus.NewGauge in pkg:golang/github.com/prometheus/client_golang@v1.19.1
Packages
Symbols
  • github.com/prometheus/client_golang/prometheus.NewGauge
Created
2026-08-26T13:30:49Z

Contract

  1. prometheus.NewGauge creates a Gauge metric collector with specified GaugeOpts
  2. Gauge.Set sets the gauge to an arbitrary float64 value
  3. Gauge.Inc and Gauge.Dec adjust the gauge value by 1
  4. Gauge.Add and Gauge.Sub adjust the gauge value by the given float64
  5. Gauge.SetToCurrentTime sets the gauge to the current Unix timestamp in seconds
  6. Registry gathers the Gauge metric with matching value and metadata

Files

  • PROMPT.md
  • csx.json
  • gauge.go
  • go.mod
  • go.sum
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

PROMPT.md
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_golang/prometheus.NewGauge in pkg:golang/github.com/prometheus/client_golang@v1.19.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/prometheus/client_golang@v1.19.1
Demonstrate these symbols/APIs:
  - github.com/prometheus/client_golang/prometheus.NewGauge

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.
csx.json
{"case":{"caseId":"case:sha256:8c33a659b0ed687142c655915e63caea302c367363756f0ded6ddf64d2a52a64","contract":["prometheus.NewGauge creates a Gauge metric collector with specified GaugeOpts","Gauge.Set sets the gauge to an arbitrary float64 value","Gauge.Inc and Gauge.Dec adjust the gauge value by 1","Gauge.Add and Gauge.Sub adjust the gauge value by the given float64","Gauge.SetToCurrentTime sets the gauge to the current Unix timestamp in seconds","Registry gathers the Gauge metric with matching value and metadata"],"goal":"verify github.com/prometheus/client_golang/prometheus.NewGauge in pkg:golang/github.com/prometheus/client_golang@v1.19.1","kind":"HOW","packages":["pkg:golang/github.com/prometheus/client_golang@v1.19.1"],"schemaVersion":1,"symbols":["github.com/prometheus/client_golang/prometheus.NewGauge"]},"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_golang@v1.19.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/prometheus/client_golang@v1.19.1","symbols":["github.com/prometheus/client_golang/prometheus.NewGauge"],"verifierAdapter":"golang@1"}
gauge.go
package sample

import (
	"github.com/prometheus/client_golang/prometheus"
)

// ProcessMonitor wraps a Prometheus Gauge metric for monitoring current resource usage.
type ProcessMonitor struct {
	Registry    *prometheus.Registry
	MemoryGauge prometheus.Gauge
}

// NewProcessMonitor initializes and registers a new Gauge metric with a custom registry.
func NewProcessMonitor(name, help string) (*ProcessMonitor, error) {
	reg := prometheus.NewRegistry()
	gauge := prometheus.NewGauge(prometheus.GaugeOpts{
		Name: name,
		Help: help,
		ConstLabels: prometheus.Labels{
			"component": "worker",
		},
	})

	if err := reg.Register(gauge); err != nil {
		return nil, err
	}

	return &ProcessMonitor{
		Registry:    reg,
		MemoryGauge: gauge,
	}, nil
}
go.mod
module sample

go 1.26.6

require (
	github.com/prometheus/client_golang v1.19.1
	github.com/prometheus/client_model v0.5.0
)

require (
	github.com/beorn7/perks v1.0.1 // indirect
	github.com/cespare/xxhash/v2 v2.2.0 // indirect
	github.com/prometheus/common v0.48.0 // indirect
	github.com/prometheus/procfs v0.12.0 // indirect
	golang.org/x/sys v0.17.0 // indirect
	google.golang.org/protobuf v1.33.0 // indirect
)
go.sum
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
spec.json
{
  "schemaVersion": 1,
  "goal": "verify github.com/prometheus/client_golang/prometheus.NewGauge in pkg:golang/github.com/prometheus/client_golang@v1.19.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/prometheus/client_golang@v1.19.1"
  ],
  "symbols": [
    "github.com/prometheus/client_golang/prometheus.NewGauge"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"time"

	"sample"

	dto "github.com/prometheus/client_model/go"
)

func main() {
	monitor, err := sample.NewProcessMonitor("worker_memory_bytes", "Current memory consumption of worker in bytes")
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create ProcessMonitor: %v\n", err)
		os.Exit(1)
	}

	// 1. Verify Set
	monitor.MemoryGauge.Set(1024.0)

	// 2. Verify Inc and Dec
	monitor.MemoryGauge.Inc()
	monitor.MemoryGauge.Dec()

	// 3. Verify Add and Sub
	monitor.MemoryGauge.Add(512.0)
	monitor.MemoryGauge.Sub(256.0)

	// 4. Verify Gather
	mfs, err := monitor.Registry.Gather()
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to gather metrics: %v\n", err)
		os.Exit(1)
	}

	if len(mfs) != 1 {
		fmt.Fprintf(os.Stderr, "expected 1 metric family, got %d\n", len(mfs))
		os.Exit(1)
	}

	mf := mfs[0]
	if mf.GetName() != "worker_memory_bytes" {
		fmt.Fprintf(os.Stderr, "expected metric name worker_memory_bytes, got %s\n", mf.GetName())
		os.Exit(1)
	}

	if mf.GetType() != dto.MetricType_GAUGE {
		fmt.Fprintf(os.Stderr, "expected metric type GAUGE, got %v\n", mf.GetType())
		os.Exit(1)
	}

	metrics := mf.GetMetric()
	if len(metrics) != 1 {
		fmt.Fprintf(os.Stderr, "expected 1 metric in family, got %d\n", len(metrics))
		os.Exit(1)
	}

	gaugeVal := metrics[0].GetGauge().GetValue()
	if gaugeVal != 1280.0 {
		fmt.Fprintf(os.Stderr, "expected gauge value 1280.0, got %f\n", gaugeVal)
		os.Exit(1)
	}

	// 5. Verify Label
	labels := metrics[0].GetLabel()
	foundComponent := false
	for _, lbl := range labels {
		if lbl.GetName() == "component" && lbl.GetValue() == "worker" {
			foundComponent = true
			break
		}
	}
	if !foundComponent {
		fmt.Fprintf(os.Stderr, "expected label component=worker not found\n")
		os.Exit(1)
	}

	// 6. Verify SetToCurrentTime
	before := float64(time.Now().UnixNano()) / 1e9
	time.Sleep(1 * time.Millisecond)
	monitor.MemoryGauge.SetToCurrentTime()
	time.Sleep(1 * time.Millisecond)
	after := float64(time.Now().UnixNano()) / 1e9

	mfsAfter, err := monitor.Registry.Gather()
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to gather after SetToCurrentTime: %v\n", err)
		os.Exit(1)
	}
	timeVal := mfsAfter[0].GetMetric()[0].GetGauge().GetValue()
	if timeVal < before || timeVal > after {
		fmt.Fprintf(os.Stderr, "expected time value between %f and %f, got %f\n", before, after, timeVal)
		os.Exit(1)
	}

	fmt.Println("All prometheus.NewGauge contract assertions passed.")
}

Origin Seeder

anonymous