示例
github.com/cyberdelia/go-metrics-graphite v0.0.0-20161219230853-39f87cc3b432: graphite.Config, graphite.Once
已验证示例 — golang github.com/cyberdelia/go-metrics-graphite v0.0.0-20161219230853-39f87cc3b432: graphite.Config, graphite.Once. contract 在 go 1.26 · linux…
sha256:22ea0c3a207feb0ed79fe189738d16267e365b43aff9232bf6e6e7f25858d709
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 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-28 |
案例
HOW- 目标
- verify pkg:golang/github.com/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432
- 符号
-
- graphite.Config
- graphite.Once
- 环境
- go 1.26.6
- 创建时间
- 2026-08-28T00:44:12Z
契约
- graphite.Config defines exporter settings with Addr, Registry, and Prefix
- graphite.Once flushes Counter and Gauge metrics to a Graphite TCP server
- graphite.Once returns an error when the TCP address is unreachable
文件
- PROMPT.md
- contract_test.go
- csx.json
- go.mod
- go.sum
- reporter.go
- spec.json
源代码
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 pkg:golang/github.com/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/github.com/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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.
package sample
import (
"bufio"
"net"
"strings"
"sync"
"testing"
"time"
"github.com/rcrowley/go-metrics"
)
func TestContract(t *testing.T) {
// 1. Verify graphite.Config defines exporter settings
registry := metrics.NewRegistry()
dummyAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("failed to resolve dummy TCP addr: %v", err)
}
cfg := NewConfig(dummyAddr, registry, "csx.app", 5*time.Second)
if cfg.Prefix != "csx.app" {
t.Fatalf("expected Prefix 'csx.app', got %q", cfg.Prefix)
}
if cfg.Registry != registry {
t.Fatalf("expected Registry to match")
}
if cfg.FlushInterval != 5*time.Second {
t.Fatalf("expected FlushInterval 5s, got %v", cfg.FlushInterval)
}
// 2. Verify graphite.Once flushes Counter and Gauge metrics to a Graphite TCP server
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("failed to start mock Graphite TCP listener: %v", err)
}
defer ln.Close()
serverAddr := ln.Addr().(*net.TCPAddr)
receivedLines := make([]string, 0)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
conn, err := ln.Accept()
if err != nil {
return
}
defer conn.Close()
scanner := bufio.NewScanner(conn)
for scanner.Scan() {
receivedLines = append(receivedLines, scanner.Text())
}
}()
counter := metrics.GetOrRegisterCounter("requests.total", registry)
counter.Inc(42)
gauge := metrics.GetOrRegisterGauge("active.workers", registry)
gauge.Update(10)
serverCfg := NewConfig(serverAddr, registry, "csx.metrics", 1*time.Second)
if err := FlushOnce(serverCfg); err != nil {
t.Fatalf("FlushOnce failed: %v", err)
}
wg.Wait()
if len(receivedLines) == 0 {
t.Fatalf("expected metric lines to be received, got none")
}
var foundCounter, foundGauge bool
for _, l := range receivedLines {
if strings.HasPrefix(l, "csx.metrics.requests.total.count 42 ") {
foundCounter = true
}
if strings.HasPrefix(l, "csx.metrics.active.workers.value 10 ") {
foundGauge = true
}
}
if !foundCounter {
t.Fatalf("expected counter metric line 'csx.metrics.requests.total.count 42 <ts>', received lines: %v", receivedLines)
}
if !foundGauge {
t.Fatalf("expected gauge metric line 'csx.metrics.active.workers.value 10 <ts>', received lines: %v", receivedLines)
}
// 3. Verify graphite.Once returns an error when the TCP address is unreachable
closedLn, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("failed to listen temporarily: %v", err)
}
closedAddr := closedLn.Addr().(*net.TCPAddr)
closedLn.Close() // immediately close to make port unreachable
unreachableCfg := NewConfig(closedAddr, registry, "csx.metrics", 1*time.Second)
if err := FlushOnce(unreachableCfg); err == nil {
t.Fatalf("expected FlushOnce to return error for unreachable address, got nil")
}
}
{"case":{"caseId":"case:sha256:fdb59031dcd9e75c48471c03338ef118556215d2e6a130c337a7c2b465d7858a","contract":["graphite.Config defines exporter settings with Addr, Registry, and Prefix","graphite.Once flushes Counter and Gauge metrics to a Graphite TCP server","graphite.Once returns an error when the TCP address is unreachable"],"goal":"verify pkg:golang/github.com/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432","kind":"HOW","packages":["pkg:golang/github.com/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432"],"schemaVersion":1,"symbols":["graphite.Config","graphite.Once"]},"contractCommand":["go","test","./..."],"environment":{"arch":"amd64","compiler":"go","compilerVersion":"1.26.6","distro":"ubuntu","ecosystem":"golang","language":"go","languageVersion":"1.26.6","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/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432"],"schemaVersion":1,"subject":"pkg:golang/github.com/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432","symbols":["graphite.Config","graphite.Once"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.26.6
require (
github.com/cyberdelia/go-metrics-graphite v0.0.0-20161219230853-39f87cc3b432
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9
)
github.com/cyberdelia/go-metrics-graphite v0.0.0-20161219230853-39f87cc3b432 h1:M5QgkYacWj0Xs8MhpIK/5uwU02icXpEoSo9sM2aRCps=
github.com/cyberdelia/go-metrics-graphite v0.0.0-20161219230853-39f87cc3b432/go.mod h1:xwIwAxMvYnVrGJPe2FKx5prTrnAjGOD8zvDOnxnrrkM=
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9 h1:bsUq1dX0N8AOIL7EB/X911+m4EHsnWEHeJ0c+3TTBrg=
github.com/rcrowley/go-metrics v0.0.0-20250401214520-65e299d6c5c9/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
package sample
import (
"net"
"time"
graphite "github.com/cyberdelia/go-metrics-graphite"
"github.com/rcrowley/go-metrics"
)
// NewConfig creates a new Graphite exporter Config.
func NewConfig(addr *net.TCPAddr, registry metrics.Registry, prefix string, flushInterval time.Duration) graphite.Config {
return graphite.Config{
Addr: addr,
Registry: registry,
FlushInterval: flushInterval,
DurationUnit: time.Millisecond,
Prefix: prefix,
Percentiles: []float64{0.5, 0.75, 0.95, 0.99},
}
}
// FlushOnce performs a single metrics flush to Graphite.
func FlushOnce(cfg graphite.Config) error {
return graphite.Once(cfg)
}
{
"schemaVersion": 1,
"goal": "verify pkg:golang/github.com/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432",
"kind": "HOW",
"packages": [
"pkg:golang/github.com/cyberdelia/go-metrics-graphite@v0.0.0-20161219230853-39f87cc3b432"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
原始种子者
匿名