Skip to content

Commit 96ce8e4

Browse files
authored
Bump Tessera & switch to OpenTelemetry (#242)
1 parent 04292ff commit 96ce8e4

File tree

12 files changed

+273
-144
lines changed

12 files changed

+273
-144
lines changed

cmd/aws/main.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"time"
2929

3030
"github.com/go-sql-driver/mysql"
31-
"github.com/prometheus/client_golang/prometheus/promhttp"
3231
sctfe "github.com/transparency-dev/static-ct"
3332
"github.com/transparency-dev/static-ct/storage"
3433
awsSCTFE "github.com/transparency-dev/static-ct/storage/aws"
@@ -50,7 +49,6 @@ var (
5049
notAfterLimit timestampFlag
5150

5251
httpEndpoint = flag.String("http_endpoint", "localhost:6962", "Endpoint for HTTP (host:port).")
53-
metricsEndpoint = flag.String("metrics_endpoint", "", "Endpoint for serving metrics; if left empty, metrics will be visible on --http_endpoint.")
5452
httpDeadline = flag.Duration("http_deadline", time.Second*10, "Deadline for HTTP requests.")
5553
maskInternalErrors = flag.Bool("mask_internal_errors", false, "Don't return error strings with Internal Server Error HTTP responses.")
5654
origin = flag.String("origin", "", "Origin of the log, for checkpoints and the monitoring prefix.")
@@ -102,25 +100,6 @@ func main() {
102100
klog.Info("**** CT HTTP Server Starting ****")
103101
http.Handle("/", logHandler)
104102

105-
metricsAt := *metricsEndpoint
106-
if metricsAt == "" {
107-
metricsAt = *httpEndpoint
108-
}
109-
110-
if metricsAt != *httpEndpoint {
111-
// Run a separate handler for metrics.
112-
go func() {
113-
mux := http.NewServeMux()
114-
mux.Handle("/metrics", promhttp.Handler())
115-
metricsServer := http.Server{Addr: metricsAt, Handler: mux}
116-
err := metricsServer.ListenAndServe()
117-
klog.Warningf("Metrics server exited: %v", err)
118-
}()
119-
} else {
120-
// Handle metrics on the DefaultServeMux.
121-
http.Handle("/metrics", promhttp.Handler())
122-
}
123-
124103
// Bring up the HTTP server and serve until we get a signal not to.
125104
srv := http.Server{Addr: *httpEndpoint}
126105
shutdownWG := new(sync.WaitGroup)

cmd/gcp/main.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"syscall"
2929
"time"
3030

31-
"github.com/prometheus/client_golang/prometheus/promhttp"
3231
sctfe "github.com/transparency-dev/static-ct"
3332
"github.com/transparency-dev/static-ct/storage"
3433
gcpSCTFE "github.com/transparency-dev/static-ct/storage/gcp"
@@ -49,7 +48,6 @@ var (
4948
notAfterLimit timestampFlag
5049

5150
httpEndpoint = flag.String("http_endpoint", "localhost:6962", "Endpoint for HTTP (host:port).")
52-
metricsEndpoint = flag.String("metrics_endpoint", "", "Endpoint for serving metrics; if left empty, metrics will be visible on --http_endpoint.")
5351
httpDeadline = flag.Duration("http_deadline", time.Second*10, "Deadline for HTTP requests.")
5452
maskInternalErrors = flag.Bool("mask_internal_errors", false, "Don't return error strings with Internal Server Error HTTP responses.")
5553
origin = flag.String("origin", "", "Origin of the log, for checkpoints and the monitoring prefix.")
@@ -63,6 +61,7 @@ var (
6361
rejectExtensions = flag.String("reject_extension", "", "A list of X.509 extension OIDs, in dotted string form (e.g. '2.3.4.5') which, if present, should cause submissions to be rejected.")
6462
signerPublicKeySecretName = flag.String("signer_public_key_secret_name", "", "Public key secret name for checkpoints and SCTs signer. Format: projects/{projectId}/secrets/{secretName}/versions/{secretVersion}.")
6563
signerPrivateKeySecretName = flag.String("signer_private_key_secret_name", "", "Private key secret name for checkpoints and SCTs signer. Format: projects/{projectId}/secrets/{secretName}/versions/{secretVersion}.")
64+
traceFraction = flag.Float64("trace_fraction", 0, "Fraction of open-telemetry span traces to sample")
6665
)
6766

6867
// nolint:staticcheck
@@ -71,6 +70,9 @@ func main() {
7170
flag.Parse()
7271
ctx := context.Background()
7372

73+
shutdownOTel := initOTel(ctx, *traceFraction)
74+
defer shutdownOTel(ctx)
75+
7476
signer, err := NewSecretManagerSigner(ctx, *signerPublicKeySecretName, *signerPrivateKeySecretName)
7577
if err != nil {
7678
klog.Exitf("Can't create secret manager signer: %v", err)
@@ -95,25 +97,6 @@ func main() {
9597
klog.Info("**** CT HTTP Server Starting ****")
9698
http.Handle("/", logHandler)
9799

98-
metricsAt := *metricsEndpoint
99-
if metricsAt == "" {
100-
metricsAt = *httpEndpoint
101-
}
102-
103-
if metricsAt != *httpEndpoint {
104-
// Run a separate handler for metrics.
105-
go func() {
106-
mux := http.NewServeMux()
107-
mux.Handle("/metrics", promhttp.Handler())
108-
metricsServer := http.Server{Addr: metricsAt, Handler: mux}
109-
err := metricsServer.ListenAndServe()
110-
klog.Warningf("Metrics server exited: %v", err)
111-
}()
112-
} else {
113-
// Handle metrics on the DefaultServeMux.
114-
http.Handle("/metrics", promhttp.Handler())
115-
}
116-
117100
// Bring up the HTTP server and serve until we get a signal not to.
118101
srv := http.Server{Addr: *httpEndpoint}
119102
shutdownWG := new(sync.WaitGroup)

cmd/gcp/otel.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2025 The Tessera authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"context"
19+
"errors"
20+
21+
"go.opentelemetry.io/otel"
22+
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
23+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
24+
25+
mexporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric"
26+
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
27+
"k8s.io/klog/v2"
28+
)
29+
30+
// initOTel initialises the open telemetry support for metrics and tracing.
31+
//
32+
// Tracing is enabled with statistical sampling, with the probability passed in.
33+
// Returns a shutdown function which should be called just before exiting the process.
34+
func initOTel(ctx context.Context, traceFraction float64) func(context.Context) {
35+
var shutdownFuncs []func(context.Context) error
36+
// shutdown combines shutdown functions from multiple OpenTelemetry
37+
// components into a single function.
38+
shutdown := func(ctx context.Context) {
39+
var err error
40+
for _, fn := range shutdownFuncs {
41+
err = errors.Join(err, fn(ctx))
42+
}
43+
shutdownFuncs = nil
44+
if err != nil {
45+
klog.Errorf("OTel shutdown: %v", err)
46+
}
47+
}
48+
49+
me, err := mexporter.New()
50+
if err != nil {
51+
klog.Exitf("Failed to create metric exporter: %v", err)
52+
return nil
53+
}
54+
// initialize a MeterProvider that periodically exports to the GCP exporter.
55+
mp := sdkmetric.NewMeterProvider(
56+
sdkmetric.WithReader(sdkmetric.NewPeriodicReader(me)),
57+
)
58+
shutdownFuncs = append(shutdownFuncs, mp.Shutdown)
59+
otel.SetMeterProvider(mp)
60+
61+
te, err := texporter.New()
62+
if err != nil {
63+
klog.Exitf("Failed to create trace exporter: %v", err)
64+
return nil
65+
}
66+
// initialize a TracerProvier that periodically exports to the GCP exporter.
67+
tp := sdktrace.NewTracerProvider(
68+
sdktrace.WithSampler(sdktrace.TraceIDRatioBased(traceFraction)),
69+
sdktrace.WithBatcher(te),
70+
)
71+
shutdownFuncs = append(shutdownFuncs, mp.Shutdown)
72+
otel.SetTracerProvider(tp)
73+
74+
return shutdown
75+
}

ctlog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func NewLogHandler(ctx context.Context, origin string, signer crypto.Signer, cfg
138138
TimeSource: sysTimeSource,
139139
}
140140

141-
handlers := scti.NewPathHandlers(opts, log)
141+
handlers := scti.NewPathHandlers(ctx, opts, log)
142142
mux := http.NewServeMux()
143143
// Register handlers for all the configured logs.
144144
for path, handler := range handlers {

go.mod

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,32 @@ go 1.24.0
44

55
require (
66
cloud.google.com/go/secretmanager v1.14.6
7-
cloud.google.com/go/spanner v1.78.0
7+
cloud.google.com/go/spanner v1.79.0
88
cloud.google.com/go/storage v1.51.0
9+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0
10+
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.27.0
911
github.com/RobinUS2/golang-moving-average v1.0.0
1012
github.com/aws/aws-sdk-go-v2 v1.36.3
1113
github.com/aws/aws-sdk-go-v2/config v1.29.13
1214
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.1
1315
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.35.3
1416
github.com/aws/smithy-go v1.22.3
1517
github.com/gdamore/tcell/v2 v2.8.1
16-
github.com/go-sql-driver/mysql v1.9.1
18+
github.com/go-sql-driver/mysql v1.9.2
1719
github.com/google/go-cmp v0.7.0
1820
github.com/kylelemons/godebug v1.1.0
19-
github.com/prometheus/client_golang v1.21.1
2021
github.com/rivo/tview v0.0.0-20240625185742-b0a7293b8130
2122
github.com/transparency-dev/formats v0.0.0-20250127084410-134797944be6
2223
github.com/transparency-dev/merkle v0.0.2
23-
github.com/transparency-dev/trillian-tessera v0.1.2-0.20250320160837-ae724376e1ac
24+
github.com/transparency-dev/trillian-tessera v0.1.2-0.20250408153912-a650aa01f2a4
2425
go.etcd.io/bbolt v1.4.0
26+
go.opentelemetry.io/otel v1.35.0
27+
go.opentelemetry.io/otel/metric v1.35.0
28+
go.opentelemetry.io/otel/sdk v1.35.0
29+
go.opentelemetry.io/otel/sdk/metric v1.35.0
2530
golang.org/x/crypto v0.37.0
2631
golang.org/x/mod v0.24.0
27-
golang.org/x/net v0.38.0
32+
golang.org/x/net v0.39.0
2833
google.golang.org/api v0.228.0
2934
google.golang.org/grpc v1.71.1
3035
k8s.io/klog/v2 v2.130.1
@@ -39,10 +44,10 @@ require (
3944
cloud.google.com/go/iam v1.4.2 // indirect
4045
cloud.google.com/go/longrunning v0.6.6 // indirect
4146
cloud.google.com/go/monitoring v1.24.1 // indirect
47+
cloud.google.com/go/trace v1.11.3 // indirect
4248
filippo.io/edwards25519 v1.1.0 // indirect
4349
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 // indirect
4450
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
45-
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0 // indirect
4651
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 // indirect
4752
github.com/avast/retry-go/v4 v4.6.1 // indirect
4853
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect
@@ -59,7 +64,6 @@ require (
5964
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
6065
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
6166
github.com/aws/aws-sdk-go-v2/service/sts v1.33.18 // indirect
62-
github.com/beorn7/perks v1.0.1 // indirect
6367
github.com/cespare/xxhash/v2 v2.3.0 // indirect
6468
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 // indirect
6569
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
@@ -75,24 +79,15 @@ require (
7579
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
7680
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
7781
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
78-
github.com/klauspost/compress v1.17.11 // indirect
7982
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
8083
github.com/mattn/go-runewidth v0.0.16 // indirect
81-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
8284
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
83-
github.com/prometheus/client_model v0.6.1 // indirect
84-
github.com/prometheus/common v0.62.0 // indirect
85-
github.com/prometheus/procfs v0.15.1 // indirect
8685
github.com/rivo/uniseg v0.4.7 // indirect
8786
go.opencensus.io v0.24.0 // indirect
8887
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
8988
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 // indirect
9089
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
9190
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
92-
go.opentelemetry.io/otel v1.35.0 // indirect
93-
go.opentelemetry.io/otel/metric v1.35.0 // indirect
94-
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
95-
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
9691
go.opentelemetry.io/otel/trace v1.35.0 // indirect
9792
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
9893
golang.org/x/oauth2 v0.28.0 // indirect

0 commit comments

Comments
 (0)