From b5fe05fe62bd13e1d7fd9f7152e294ebd854c03a Mon Sep 17 00:00:00 2001 From: Al Cutter Date: Tue, 16 Jun 2026 10:46:24 +0100 Subject: [PATCH] Switch from prometheus counters to OTel internally --- cmd/feedwitness/main.go | 13 ++-- cmd/feedwitness/otel.go | 32 ++++++++++ cmd/feedwitness/run_feeders.go | 49 ++++++++------- cmd/feedwitness/run_feeders_test.go | 4 -- cmd/omniwitness/monolith.go | 15 ++--- cmd/omniwitness_gcp/main.go | 13 ++-- go.mod | 20 ++++--- go.sum | 42 +++++++------ internal/bastion/bastion.go | 35 +++++------ internal/bastion/otel.go | 30 ++++++++++ monitoring/inert.go | 60 ------------------- monitoring/metrics.go | 60 ------------------- monitoring/prometheus/metrics.go | 92 ----------------------------- omniwitness/distribute.go | 30 +++++----- omniwitness/distribute_test.go | 2 - omniwitness/otel.go | 30 ++++++++++ witness/http.go | 3 - witness/http_test.go | 2 +- witness/otel.go | 30 ++++++++++ witness/witness.go | 51 ++++++++-------- witness/witness_test.go | 2 - 21 files changed, 266 insertions(+), 349 deletions(-) create mode 100644 cmd/feedwitness/otel.go create mode 100644 internal/bastion/otel.go delete mode 100644 monitoring/inert.go delete mode 100644 monitoring/metrics.go delete mode 100644 monitoring/prometheus/metrics.go create mode 100644 omniwitness/otel.go create mode 100644 witness/otel.go diff --git a/cmd/feedwitness/main.go b/cmd/feedwitness/main.go index d63dde50..2e757941 100644 --- a/cmd/feedwitness/main.go +++ b/cmd/feedwitness/main.go @@ -35,9 +35,10 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" w_http "github.com/transparency-dev/witness/client/http" "github.com/transparency-dev/witness/witness" - "github.com/transparency-dev/witness/monitoring" - "github.com/transparency-dev/witness/monitoring/prometheus" "github.com/transparency-dev/witness/omniwitness" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/prometheus" + "go.opentelemetry.io/otel/sdk/metric" "k8s.io/klog/v2" ) @@ -70,10 +71,12 @@ func main() { } if *metricsAddr != "" { - mf := prometheus.MetricFactory{ - Prefix: "omnifeeder_", + exporter, err := prometheus.New(prometheus.WithNamespace("omnifeeder")) + if err != nil { + klog.Fatalf("failed to create prometheus exporter: %v", err) } - monitoring.SetMetricFactory(mf) + provider := metric.NewMeterProvider(metric.WithReader(exporter)) + otel.SetMeterProvider(provider) http.Handle("/metrics", promhttp.Handler()) go func() { diff --git a/cmd/feedwitness/otel.go b/cmd/feedwitness/otel.go new file mode 100644 index 00000000..9f13687b --- /dev/null +++ b/cmd/feedwitness/otel.go @@ -0,0 +1,32 @@ +// Copyright 2026 The Witness authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" +) + +const name = "github.com/transparency-dev/witness/cmd/feedwitness" + +var ( + meter = otel.Meter(name) +) + +var ( + witnessKey = attribute.Key("witness.name") + logKey = attribute.Key("witness.log_origin") + statusKey = attribute.Key("witness.status") +) diff --git a/cmd/feedwitness/run_feeders.go b/cmd/feedwitness/run_feeders.go index 0fa9ad0c..71a62376 100644 --- a/cmd/feedwitness/run_feeders.go +++ b/cmd/feedwitness/run_feeders.go @@ -22,7 +22,6 @@ import ( "net/http" "regexp" "strings" - "sync" "github.com/cenkalti/backoff/v5" "github.com/transparency-dev/formats/log" @@ -33,8 +32,8 @@ import ( "github.com/transparency-dev/witness/internal/feeder/sumdb" "github.com/transparency-dev/witness/internal/feeder/tiles" "github.com/transparency-dev/witness/witness" - "github.com/transparency-dev/witness/monitoring" "github.com/transparency-dev/witness/omniwitness" + "go.opentelemetry.io/otel/metric" "golang.org/x/mod/sumdb/note" "golang.org/x/sync/errgroup" "golang.org/x/time/rate" @@ -42,23 +41,20 @@ import ( ) var ( - feederDoOnce sync.Once - counterFeedRequest monitoring.Counter - counterFeedResponse monitoring.Counter + counterFeedRequest metric.Int64Counter + counterFeedResponse metric.Int64Counter ) -func initFeederMetrics() { - feederDoOnce.Do(func() { - mf := monitoring.GetMetricFactory() - const ( - witness = "witness" - log = "log" - status = "status" - ) - - counterFeedRequest = mf.NewCounter("feed_request", "Number of Feed requests sent to witnesses", witness, log) - counterFeedResponse = mf.NewCounter("feed_response", "Witness responses", witness, log, status) - }) +func init() { + var err error + counterFeedRequest, err = meter.Int64Counter("feed_request", metric.WithUnit("{call}"), metric.WithDescription("Number of Feed requests sent to witnesses")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } + counterFeedResponse, err = meter.Int64Counter("feed_response", metric.WithUnit("{call}"), metric.WithDescription("Witness responses")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } } type feederConfig struct { @@ -99,8 +95,6 @@ type wJob struct { // // This is a long-running function which will only return when the context is done. func runFeeders(ctx context.Context, opts runFeedOpts) error { - initFeederMetrics() - if opts.HTTPClient == nil { opts.HTTPClient = http.DefaultClient } @@ -133,7 +127,10 @@ func runFeeders(ctx context.Context, opts runFeedOpts) error { case job := <-wChan: var err error sizeHint := logSizes[job.logOrigin] - counterFeedRequest.Inc(wi.Name, job.logOrigin) + counterFeedRequest.Add(ctx, 1, metric.WithAttributes( + witnessKey.String(wi.Name), + logKey.String(job.logOrigin), + )) sizeHint, err = job.f(sizeHint, wi) if err != nil { // Log this, but don't return the error as we want to continue @@ -250,12 +247,20 @@ func submitToWitness(ctx context.Context, sizeHint uint64, cpRaw []byte, cpSubmi klog.V(2).Infof("%q: Fetched proof %d -> %d: %x", cpSubmit.Origin, sizeHint, cpSubmit.Size, conP) _, actualSize, err := w.Update(ctx, sizeHint, cpRaw, conP) - counterFeedResponse.Inc(w.Name, cpSubmit.Origin, statusForError(err)) + counterFeedResponse.Add(ctx, 1, metric.WithAttributes( + witnessKey.String(w.Name), + logKey.String(cpSubmit.Origin), + statusKey.String(statusForError(err)), + )) switch { case errors.Is(err, witness.ErrCheckpointStale): klog.V(2).Infof("%q: %d is stale, bumping to %d: %x", cpSubmit.Origin, sizeHint, cpSubmit.Size, conP) sizeHint = actualSize - counterFeedResponse.Inc(w.Name, cpSubmit.Origin, "stale") + counterFeedResponse.Add(ctx, 1, metric.WithAttributes( + witnessKey.String(w.Name), + logKey.String(cpSubmit.Origin), + statusKey.String("stale"), + )) return sizeHint, backoff.RetryAfter(1) case err != nil: e := fmt.Errorf("%q: failed to submit checkpoint to witness: %w", cpSubmit.Origin, err) diff --git a/cmd/feedwitness/run_feeders_test.go b/cmd/feedwitness/run_feeders_test.go index 214bac91..c533889d 100644 --- a/cmd/feedwitness/run_feeders_test.go +++ b/cmd/feedwitness/run_feeders_test.go @@ -26,14 +26,10 @@ import ( "github.com/transparency-dev/serverless-log/testdata" "github.com/transparency-dev/witness/internal/feeder" "github.com/transparency-dev/witness/witness" - "github.com/transparency-dev/witness/monitoring" "golang.org/x/mod/sumdb/note" ) func TestFeedOnce(t *testing.T) { - monitoring.SetMetricFactory(monitoring.InertMetricFactory{}) - initFeederMetrics() - ctx := context.Background() for _, test := range []struct { desc string diff --git a/cmd/omniwitness/monolith.go b/cmd/omniwitness/monolith.go index 7a927bf5..7533581a 100644 --- a/cmd/omniwitness/monolith.go +++ b/cmd/omniwitness/monolith.go @@ -33,9 +33,10 @@ import ( f_note "github.com/transparency-dev/formats/note" "github.com/transparency-dev/witness/persistence/inmemory" psql "github.com/transparency-dev/witness/persistence/sqlite" - "github.com/transparency-dev/witness/monitoring" - "github.com/transparency-dev/witness/monitoring/prometheus" "github.com/transparency-dev/witness/omniwitness" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/prometheus" + "go.opentelemetry.io/otel/sdk/metric" "golang.org/x/mod/sumdb/note" "k8s.io/klog/v2" @@ -80,13 +81,13 @@ func main() { if *metricsAddr == "" { klog.Info("No metrics_listen address provided so skipping prometheus setup") - mf := monitoring.InertMetricFactory{} - monitoring.SetMetricFactory(mf) } else { - mf := prometheus.MetricFactory{ - Prefix: "omniwitness_", + exporter, err := prometheus.New(prometheus.WithNamespace("omniwitness")) + if err != nil { + klog.Fatalf("failed to create prometheus exporter: %v", err) } - monitoring.SetMetricFactory(mf) + provider := metric.NewMeterProvider(metric.WithReader(exporter)) + otel.SetMeterProvider(provider) go func() { http.Handle("/metrics", promhttp.Handler()) diff --git a/cmd/omniwitness_gcp/main.go b/cmd/omniwitness_gcp/main.go index 836fead4..14787f6d 100644 --- a/cmd/omniwitness_gcp/main.go +++ b/cmd/omniwitness_gcp/main.go @@ -25,10 +25,11 @@ import ( "time" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/transparency-dev/witness/monitoring" - "github.com/transparency-dev/witness/monitoring/prometheus" "github.com/transparency-dev/witness/omniwitness" "github.com/transparency-dev/witness/persistence/spanner" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/exporters/prometheus" + "go.opentelemetry.io/otel/sdk/metric" "golang.org/x/mod/sumdb/note" "k8s.io/klog/v2" ) @@ -57,10 +58,12 @@ func main() { ctx := context.Background() - mf := prometheus.MetricFactory{ - Prefix: "omniwitness_", + exporter, err := prometheus.New(prometheus.WithNamespace("omniwitness")) + if err != nil { + klog.Fatalf("failed to create prometheus exporter: %v", err) } - monitoring.SetMetricFactory(mf) + provider := metric.NewMeterProvider(metric.WithReader(exporter)) + otel.SetMeterProvider(provider) mux := &http.ServeMux{} mux.Handle("/metrics", promhttp.Handler()) klog.Infof("Prometheus configured on %s", *addr) diff --git a/go.mod b/go.mod index 390ff707..ef2eb0d1 100644 --- a/go.mod +++ b/go.mod @@ -14,6 +14,10 @@ require ( github.com/transparency-dev/merkle v0.0.3-0.20240919113952-3c979d16ee14 github.com/transparency-dev/serverless-log v0.0.0-20250425165558-64e1d2007a10 github.com/transparency-dev/tessera v1.0.3-0.20260303172654-b64a6fdf82f4 + go.opentelemetry.io/otel v1.44.0 + go.opentelemetry.io/otel/exporters/prometheus v0.66.0 + go.opentelemetry.io/otel/metric v1.44.0 + go.opentelemetry.io/otel/sdk/metric v1.44.0 golang.org/x/mod v0.36.0 golang.org/x/net v0.54.0 golang.org/x/sync v0.20.0 @@ -52,23 +56,21 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/prometheus/client_model v0.6.2 // indirect - github.com/prometheus/common v0.66.1 // indirect - github.com/prometheus/procfs v0.16.1 // indirect + github.com/prometheus/common v0.67.5 // indirect + github.com/prometheus/otlptranslator v1.0.0 // indirect + github.com/prometheus/procfs v0.20.1 // indirect github.com/spiffe/go-spiffe/v2 v2.6.0 // indirect go.opencensus.io v0.24.0 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect go.opentelemetry.io/contrib/detectors/gcp v1.42.0 // indirect go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 // indirect - go.opentelemetry.io/otel v1.43.0 // indirect - go.opentelemetry.io/otel/metric v1.43.0 // indirect - go.opentelemetry.io/otel/sdk v1.43.0 // indirect - go.opentelemetry.io/otel/sdk/metric v1.43.0 // indirect - go.opentelemetry.io/otel/trace v1.43.0 // indirect - go.yaml.in/yaml/v2 v2.4.2 // indirect + go.opentelemetry.io/otel/sdk v1.44.0 // indirect + go.opentelemetry.io/otel/trace v1.44.0 // indirect + go.yaml.in/yaml/v2 v2.4.4 // indirect golang.org/x/crypto v0.51.0 // indirect golang.org/x/oauth2 v0.36.0 // indirect - golang.org/x/sys v0.44.0 // indirect + golang.org/x/sys v0.45.0 // indirect golang.org/x/text v0.37.0 // indirect google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect diff --git a/go.sum b/go.sum index 15ec6560..bcd9d6b8 100644 --- a/go.sum +++ b/go.sum @@ -123,10 +123,12 @@ github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UH github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= -github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs= -github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA= -github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg= -github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is= +github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4= +github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw= +github.com/prometheus/otlptranslator v1.0.0 h1:s0LJW/iN9dkIH+EnhiD3BlkkP5QVIUVEoIwkU+A6qos= +github.com/prometheus/otlptranslator v1.0.0/go.mod h1:vRYWnXvI6aWGpsdY/mOT/cbeVRBlPWtBNDb7kGR3uKM= +github.com/prometheus/procfs v0.20.1 h1:XwbrGOIplXW/AU3YhIhLODXMJYyC1isLFfYCsTEycfc= +github.com/prometheus/procfs v0.20.1/go.mod h1:o9EMBZGRyvDrSPH1RqdxhojkuXstoe4UlK79eF5TGGo= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/spiffe/go-spiffe/v2 v2.6.0 h1:l+DolpxNWYgruGQVV0xsfeya3CsC7m8iBzDnMpsbLuo= @@ -157,20 +159,24 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.6 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0/go.mod h1:NoUCKYWK+3ecatC4HjkRktREheMeEtrXoQxrqYFeHSc= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 h1:OyrsyzuttWTSur2qN/Lm0m2a8yqyIjUVBZcxFPuXq2o= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0/go.mod h1:C2NGBr+kAB4bk3xtMXfZ94gqFDtg/GkI7e9zqGh5Beg= -go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= -go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= -go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= -go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= -go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= -go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg= -go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= -go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= -go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= -go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= +go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU= +go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc= +go.opentelemetry.io/otel/exporters/prometheus v0.66.0 h1:vkrK8PAznv2NKt2r+kdu252ccGzkEqLc2aSXbQIALYQ= +go.opentelemetry.io/otel/exporters/prometheus v0.66.0/go.mod h1:V/UB6D3vMF/UBOL5igAsAYnk1nG/bzYYTzvsB16cy7o= +go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc= +go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo= +go.opentelemetry.io/otel/metric/x v0.66.0 h1:YkCrx1zLOChi9ZcZ6euupOcsgzbVlec7D/xoEU1+cTA= +go.opentelemetry.io/otel/metric/x v0.66.0/go.mod h1:d1+BDj9t96do0/1LoU1ayfCv79ZgNE41qbhBvnMOBZk= +go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58= +go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0= +go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI= +go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA= +go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk= +go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= -go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= +go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= +go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI= @@ -203,8 +209,8 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ= -golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= +golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= diff --git a/internal/bastion/bastion.go b/internal/bastion/bastion.go index 11815070..001b9de3 100644 --- a/internal/bastion/bastion.go +++ b/internal/bastion/bastion.go @@ -27,10 +27,9 @@ import ( "math/big" "net" "net/http" - "sync" "time" - "github.com/transparency-dev/witness/monitoring" + "go.opentelemetry.io/otel/metric" "golang.org/x/mod/sumdb/note" "golang.org/x/net/http2" "k8s.io/klog/v2" @@ -48,37 +47,33 @@ type Config struct { // If the connection to the bastion is broken for any reason, it will be retried. // This function returns only once the provided context is done. func Register(ctx context.Context, c Config, witnessHandler http.Handler) error { - initMetrics() klog.Infof("My bastion backend ID: %064x", sha256.Sum256(c.BastionKey.Public().(ed25519.PublicKey))) return connectAndServe(ctx, c.Addr, witnessHandler, c.BastionKey) } var ( - doOnce sync.Once - counterBastionRegisterAttempt monitoring.Counter - counterBastionRegisterSuccess monitoring.Counter + counterBastionRegisterAttempt metric.Int64Counter + counterBastionRegisterSuccess metric.Int64Counter ) -func initMetrics() { - doOnce.Do(func() { - mf := monitoring.GetMetricFactory() - const ( - bastionID = "bastionid" - origin = "origin" - status = "status" - ) - - counterBastionRegisterAttempt = mf.NewCounter("bastion_register_attempt", "Number of attempts to register with bastion", bastionID) - counterBastionRegisterSuccess = mf.NewCounter("bastion_register_success", "Number of successful registrations with bastion", bastionID) - }) +func init() { + var err error + counterBastionRegisterAttempt, err = meter.Int64Counter("bastion_register_attempt", metric.WithUnit("{call}"), metric.WithDescription("Number of attempts to register with bastion")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } + counterBastionRegisterSuccess, err = meter.Int64Counter("bastion_register_success", metric.WithUnit("{call}"), metric.WithDescription("Number of successful registrations with bastion")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } } func connectAndServe(ctx context.Context, host string, handler http.Handler, key ed25519.PrivateKey) error { t := time.NewTicker(5 * time.Second) defer t.Stop() for { - counterBastionRegisterAttempt.Inc(host) + counterBastionRegisterAttempt.Add(ctx, 1, metric.WithAttributes(bastionKey.String(host))) select { case <-ctx.Done(): return ctx.Err() @@ -114,7 +109,7 @@ func connectAndServe(ctx context.Context, host string, handler http.Handler, key } klog.Infof("Connected to bastion. Serving connection...") - counterBastionRegisterSuccess.Inc(host) + counterBastionRegisterSuccess.Add(ctx, 1, metric.WithAttributes(bastionKey.String(host))) (&http2.Server{ IdleTimeout: 300 * time.Second, ReadIdleTimeout: 10 * time.Second, diff --git a/internal/bastion/otel.go b/internal/bastion/otel.go new file mode 100644 index 00000000..444194c3 --- /dev/null +++ b/internal/bastion/otel.go @@ -0,0 +1,30 @@ +// Copyright 2026 The Witness authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package bastion + +import ( + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" +) + +const name = "github.com/transparency-dev/witness/bastion" + +var ( + meter = otel.Meter(name) +) + +var ( + bastionKey = attribute.Key("bastion.id") +) diff --git a/monitoring/inert.go b/monitoring/inert.go deleted file mode 100644 index cf36a4e8..00000000 --- a/monitoring/inert.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2023 Google LLC. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package monitoring - -import ( - "fmt" - "strings" - "sync" - - "k8s.io/klog/v2" -) - -// InertMetricFactory creates inert metrics for testing. -type InertMetricFactory struct{} - -// NewCounter creates a new inert Counter. -func (imf InertMetricFactory) NewCounter(name, help string, labelNames ...string) Counter { - return &InertCounter{ - labelCount: len(labelNames), - vals: make(map[string]uint64), - } -} - -// InertCounter is an internal-only implementation of both the Counter and Gauge interfaces. -type InertCounter struct { - labelCount int - mu sync.Mutex - vals map[string]uint64 -} - -// Inc adds 1 to the value. -func (m *InertCounter) Inc(labelVals ...string) { - m.mu.Lock() - defer m.mu.Unlock() - key, err := keyForLabels(labelVals, m.labelCount) - if err != nil { - klog.Error(err.Error()) - return - } - m.vals[key] += 1 -} - -func keyForLabels(labelVals []string, count int) (string, error) { - if len(labelVals) != count { - return "", fmt.Errorf("invalid label count %d; want %d", len(labelVals), count) - } - return strings.Join(labelVals, "|"), nil -} diff --git a/monitoring/metrics.go b/monitoring/metrics.go deleted file mode 100644 index ff2c2022..00000000 --- a/monitoring/metrics.go +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2023 Google LLC. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package monitoring contains interfaces and bindings for collecting metrics -// about behaviour of the witness. -// This package is a stripped down fork of the monitoring code from trillian. -// If more types of metrics are needed then it could be that copying all of -// that code is the pragmatic solution. -package monitoring - -import "sync" - -var ( - once sync.Once - mf MetricFactory -) - -// SetMetricFactory sets a singleton instance of a MetricFactory that will -// be used throughout the application. Only the first call to this method -// will have any effect and it _must_ be called. -func SetMetricFactory(imf MetricFactory) { - if imf == nil { - panic("MetricFactory cannot be nil") - } - once.Do(func() { - mf = imf - }) -} - -// GetMetricFactory returns the singleton MetricFactory for this application. -// Code should not call this during static initialization as the main program -// is unlikely to have configured the factory by this time. The recommended -// pattern is to call this in a `sync.Once` before initializing counters. -func GetMetricFactory() MetricFactory { - if mf == nil { - panic("SetMetricFactory not called before GetMetricFactory") - } - return mf -} - -// MetricFactory allows the creation of different types of metric. -type MetricFactory interface { - NewCounter(name, help string, labelNames ...string) Counter -} - -// Counter is a metric class for numeric values that increase. -type Counter interface { - Inc(labelVals ...string) -} diff --git a/monitoring/prometheus/metrics.go b/monitoring/prometheus/metrics.go deleted file mode 100644 index 921c4972..00000000 --- a/monitoring/prometheus/metrics.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2023 Google LLC. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package prometheus contains bindings to prometheus for the interfaces in -// the parent monitoring package. -package prometheus - -import ( - "fmt" - - "github.com/prometheus/client_golang/prometheus" - "github.com/transparency-dev/witness/monitoring" - "k8s.io/klog/v2" -) - -// MetricFactory allows the creation of Prometheus-based metrics. -type MetricFactory struct { - // Prefix is an identifier that will be used before local metric names that - // are reported. It is strongly recommended that this ends with a valid - // separator (e.g. "_") in order to improve readability; no separator is - // added by this library. - Prefix string -} - -// NewCounter creates a new Counter object backed by Prometheus. -func (pmf MetricFactory) NewCounter(name, help string, labelNames ...string) monitoring.Counter { - if len(labelNames) == 0 { - counter := prometheus.NewCounter( - prometheus.CounterOpts{ - Name: pmf.Prefix + name, - Help: help, - }) - prometheus.MustRegister(counter) - return &Counter{single: counter} - } - - vec := prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: pmf.Prefix + name, - Help: help, - }, - labelNames) - prometheus.MustRegister(vec) - return &Counter{labelNames: labelNames, vec: vec} - -} - -// Counter is a wrapper around a Prometheus Counter or CounterVec object. -type Counter struct { - labelNames []string - single prometheus.Counter - vec *prometheus.CounterVec -} - -// Inc adds 1 to a counter. -func (m *Counter) Inc(labelVals ...string) { - labels, err := labelsFor(m.labelNames, labelVals) - if err != nil { - klog.Error(err.Error()) - return - } - if m.vec != nil { - m.vec.With(labels).Inc() - } else { - m.single.Inc() - } -} - -func labelsFor(names, values []string) (prometheus.Labels, error) { - if len(names) != len(values) { - return nil, fmt.Errorf("got %d (%v) values for %d labels (%v)", len(values), values, len(names), names) - } - if len(names) == 0 { - return nil, nil - } - labels := make(prometheus.Labels) - for i, name := range names { - labels[name] = values[i] - } - return labels, nil -} diff --git a/omniwitness/distribute.go b/omniwitness/distribute.go index 24444d19..c7bb0853 100644 --- a/omniwitness/distribute.go +++ b/omniwitness/distribute.go @@ -22,10 +22,9 @@ import ( "iter" "net/http" "net/url" - "sync" f_log "github.com/transparency-dev/formats/log" - "github.com/transparency-dev/witness/monitoring" + "go.opentelemetry.io/otel/metric" "golang.org/x/mod/sumdb/note" "golang.org/x/time/rate" "k8s.io/klog/v2" @@ -45,18 +44,20 @@ const ( type getLatestCheckpointFn func(ctx context.Context, logID string) ([]byte, error) var ( - doOnce sync.Once - counterDistRestAttempt monitoring.Counter - counterDistRestSuccess monitoring.Counter + counterDistRestAttempt metric.Int64Counter + counterDistRestSuccess metric.Int64Counter ) -func initMetrics() { - doOnce.Do(func() { - mf := monitoring.GetMetricFactory() - const logIDLabel = "logid" - counterDistRestAttempt = mf.NewCounter("distribute_rest_attempt", "Number of attempts the RESTful distributor has made for the log ID", logIDLabel) - counterDistRestSuccess = mf.NewCounter("distribute_rest_success", "Number of times the RESTful distributor has succeeded for the log ID", logIDLabel) - }) +func init() { + var err error + counterDistRestAttempt, err = meter.Int64Counter("distribute_rest_attempt", metric.WithUnit("{call}"), metric.WithDescription("Number of attempts the RESTful distributor has made for the log ID")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } + counterDistRestSuccess, err = meter.Int64Counter("distribute_rest_success", metric.WithUnit("{call}"), metric.WithDescription("Number of times the RESTful distributor has succeeded for the log ID")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } } // logsFn should return the _current_ set of logs whose checkpoints should be distributed. @@ -65,7 +66,6 @@ type logsFn func(context.Context) iter.Seq2[Log, error] // newDistributor creates a new Distributor from the given configuration. func newDistributor(baseURL string, client *http.Client, logs logsFn, witSigV note.Verifier, getLatest getLatestCheckpointFn, rateLimit float64) (*distributor, error) { - initMetrics() return &distributor{ baseURL: baseURL, client: client, @@ -112,7 +112,7 @@ func (d *distributor) DistributeOnce(ctx context.Context) error { func (d *distributor) distributeForLog(ctx context.Context, l Log) error { logID := f_log.ID(l.Origin) - counterDistRestAttempt.Inc(l.Origin) + counterDistRestAttempt.Add(ctx, 1, metric.WithAttributes(logKey.String(l.Origin))) wRaw, err := d.getLatest(ctx, l.Origin) if err != nil { @@ -147,6 +147,6 @@ func (d *distributor) distributeForLog(ctx context.Context, l Log) error { return fmt.Errorf("bad status response (%s): %q", resp.Status, body) } klog.V(1).Infof("Distributed checkpoint via REST for %q (%s)", l.Verifier.Name(), l.Origin) - counterDistRestSuccess.Inc(l.Origin) + counterDistRestSuccess.Add(ctx, 1, metric.WithAttributes(logKey.String(l.Origin))) return nil } diff --git a/omniwitness/distribute_test.go b/omniwitness/distribute_test.go index f706d983..719aa0f8 100644 --- a/omniwitness/distribute_test.go +++ b/omniwitness/distribute_test.go @@ -26,7 +26,6 @@ import ( "github.com/gorilla/mux" f_log "github.com/transparency-dev/formats/log" f_note "github.com/transparency-dev/formats/note" - "github.com/transparency-dev/witness/monitoring" "golang.org/x/mod/sumdb/note" ) @@ -39,7 +38,6 @@ const ( ) func TestDistributeOnce(t *testing.T) { - monitoring.SetMetricFactory(monitoring.InertMetricFactory{}) fd := &fakeDistributor{} r := mux.NewRouter() r.HandleFunc(fmt.Sprintf(httpCheckpointByWitness, "{logid:[a-zA-Z0-9-]+}", "{witid:[^ +]+}"), fd.update).Methods(http.MethodPut) diff --git a/omniwitness/otel.go b/omniwitness/otel.go new file mode 100644 index 00000000..45970918 --- /dev/null +++ b/omniwitness/otel.go @@ -0,0 +1,30 @@ +// Copyright 2026 The Witness authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package omniwitness + +import ( + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" +) + +const name = "github.com/transparency-dev/witness/omniwitness" + +var ( + meter = otel.Meter(name) +) + +var ( + logKey = attribute.Key("witness.log_origin") +) diff --git a/witness/http.go b/witness/http.go index 11a889fc..f6932f20 100644 --- a/witness/http.go +++ b/witness/http.go @@ -22,7 +22,6 @@ import ( "fmt" "io" "net/http" - ) // maxRequestBodyBytes is the limit on the number of bytes we'll read from incoming requests. @@ -38,7 +37,6 @@ type HTTPHandler struct { witness witness } - // AddCheckpoint is a http.Handler which speaks the tlog-witness protocol for add-checkpoint. func (a *HTTPHandler) AddCheckpoint(w http.ResponseWriter, r *http.Request) { defer func() { @@ -143,4 +141,3 @@ func parseBody(r io.Reader) (uint64, [][]byte, []byte, error) { type witness interface { Update(ctx context.Context, oldSize uint64, newCP []byte, proof [][]byte) ([]byte, uint64, error) } - diff --git a/witness/http_test.go b/witness/http_test.go index b3fc63c5..551f3876 100644 --- a/witness/http_test.go +++ b/witness/http_test.go @@ -128,7 +128,7 @@ func TestHandler(t *testing.T) { } { t.Run(test.name, func(t *testing.T) { a := HTTPHandler{ - witness: test.witness, + witness: test.witness, } sc, body, ct, err := a.handleUpdate(context.Background(), 0, []byte(testCP), [][]byte{}) if err != nil { diff --git a/witness/otel.go b/witness/otel.go new file mode 100644 index 00000000..6772aaed --- /dev/null +++ b/witness/otel.go @@ -0,0 +1,30 @@ +// Copyright 2026 The Witness authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package witness + +import ( + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" +) + +const name = "github.com/transparency-dev/witness" + +var ( + meter = otel.Meter(name) +) + +var ( + originKey = attribute.Key("witness.log_origin") +) diff --git a/witness/witness.go b/witness/witness.go index 4e036b16..b9e9406c 100644 --- a/witness/witness.go +++ b/witness/witness.go @@ -25,24 +25,22 @@ import ( "errors" "fmt" "strings" - "sync" "unicode" "unicode/utf8" "github.com/transparency-dev/formats/log" "github.com/transparency-dev/merkle/proof" "github.com/transparency-dev/merkle/rfc6962" - "github.com/transparency-dev/witness/monitoring" + "go.opentelemetry.io/otel/metric" "golang.org/x/mod/sumdb/note" "k8s.io/klog/v2" ) var ( - doOnce sync.Once - counterUpdateAttempt monitoring.Counter - counterUpdateSuccess monitoring.Counter - counterInvalidConsistency monitoring.Counter - counterInconsistentCheckpoints monitoring.Counter + counterUpdateAttempt metric.Int64Counter + counterUpdateSuccess metric.Int64Counter + counterInvalidConsistency metric.Int64Counter + counterInconsistentCheckpoints metric.Int64Counter ) var ( @@ -66,15 +64,24 @@ var ( ErrPushback = errors.New("pushback") ) -func initMetrics() { - doOnce.Do(func() { - mf := monitoring.GetMetricFactory() - const logOriginLabel = "log_origin" - counterUpdateAttempt = mf.NewCounter("witness_update_request", "Number of attempted requests made to update checkpoints for the log origin", logOriginLabel) - counterUpdateSuccess = mf.NewCounter("witness_update_success", "Number of successful requests made to update checkpoints for the log origin", logOriginLabel) - counterInvalidConsistency = mf.NewCounter("witness_update_invalid_consistency", "Number of times the witness received a bad consistency proof for the log origin", logOriginLabel) - counterInconsistentCheckpoints = mf.NewCounter("witness_update_inconsistent_checkpoints", "Number of times the witness received inconsistent checkpoints for the log origin", logOriginLabel) - }) +func init() { + var err error + counterUpdateAttempt, err = meter.Int64Counter("witness_update_request", metric.WithUnit("{call}"), metric.WithDescription("Number of attempted requests made to update checkpoints for the log origin")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } + counterUpdateSuccess, err = meter.Int64Counter("witness_update_success", metric.WithUnit("{call}"), metric.WithDescription("Number of successful requests made to update checkpoints for the log origin")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } + counterInvalidConsistency, err = meter.Int64Counter("witness_update_invalid_consistency", metric.WithUnit("{call}"), metric.WithDescription("Number of times the witness received a bad consistency proof for the log origin")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } + counterInconsistentCheckpoints, err = meter.Int64Counter("witness_update_inconsistent_checkpoints", metric.WithUnit("{call}"), metric.WithDescription("Number of times the witness received inconsistent checkpoints for the log origin")) + if err != nil { + klog.Errorf("failed to create counter: %v", err) + } } // Opts is the options passed to a witness. @@ -94,8 +101,6 @@ type Witness struct { // New creates a new witness, which initially has no logs to follow. func New(ctx context.Context, wo Opts) (*Witness, error) { - initMetrics() - // Create the chkpts table if needed. if err := wo.Persistence.Init(ctx); err != nil { return nil, fmt.Errorf("Persistence.Init(): %v", err) @@ -153,7 +158,7 @@ func (w *Witness) Update(ctx context.Context, oldSize uint64, nextRaw []byte, cP return nil, 0, err } - counterUpdateAttempt.Inc(origin) + counterUpdateAttempt.Add(ctx, 1, metric.WithAttributes(originKey.String(origin))) var retSigs []byte var retSize uint64 @@ -170,7 +175,6 @@ func (w *Witness) Update(ctx context.Context, oldSize uint64, nextRaw []byte, cP if err != nil { return nil, fmt.Errorf("couldn't sign input checkpoint: %v", err) } - counterUpdateSuccess.Inc(origin) retSigs = sigs return signed, nil } @@ -202,7 +206,7 @@ func (w *Witness) Update(ctx context.Context, oldSize uint64, nextRaw []byte, cP if next.Size == prev.Size { if !bytes.Equal(next.Hash, prev.Hash) { klog.Errorf("%s: INCONSISTENT CHECKPOINTS!:\n%v\n%v", origin, prev, next) - counterInconsistentCheckpoints.Inc(origin) + counterInconsistentCheckpoints.Add(ctx, 1, metric.WithAttributes(originKey.String(origin))) retSize, retSigs = 0, nil return nil, ErrRootMismatch @@ -224,7 +228,6 @@ func (w *Witness) Update(ctx context.Context, oldSize uint64, nextRaw []byte, cP return nil, fmt.Errorf("couldn't sign input checkpoint: %v", err) } retSize, retSigs = 0, sigs - counterUpdateSuccess.Inc(origin) return signed, nil } @@ -232,7 +235,7 @@ func (w *Witness) Update(ctx context.Context, oldSize uint64, nextRaw []byte, cP // valid so we verify the consistency proofs. if err := proof.VerifyConsistency(rfc6962.DefaultHasher, prev.Size, next.Size, cProof, prev.Hash, next.Hash); err != nil { // Complain if the checkpoints aren't consistent. - counterInvalidConsistency.Inc(origin) + counterInvalidConsistency.Add(ctx, 1, metric.WithAttributes(originKey.String(origin))) return nil, ErrInvalidProof } // If the consistency proof is good we store the witness cosigned nextRaw. @@ -245,7 +248,7 @@ func (w *Witness) Update(ctx context.Context, oldSize uint64, nextRaw []byte, cP return signed, nil }) if err == nil { - counterUpdateSuccess.Inc(origin) + counterUpdateSuccess.Add(ctx, 1, metric.WithAttributes(originKey.String(origin))) } return retSigs, retSize, err diff --git a/witness/witness_test.go b/witness/witness_test.go index 87a2ee5b..9c430b82 100644 --- a/witness/witness_test.go +++ b/witness/witness_test.go @@ -27,7 +27,6 @@ import ( "github.com/transparency-dev/formats/log" f_note "github.com/transparency-dev/formats/note" "github.com/transparency-dev/merkle/rfc6962" - "github.com/transparency-dev/witness/monitoring" "golang.org/x/mod/sumdb/note" ) @@ -105,7 +104,6 @@ func dh(h string, expLen int) []byte { } func TestGetChkpt(t *testing.T) { - monitoring.SetMetricFactory(monitoring.InertMetricFactory{}) for _, test := range []struct { desc string setOrigin string