Skip to content

Bump Tessera & switch to OpenTelemetry #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions cmd/aws/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"time"

"github.com/go-sql-driver/mysql"
"github.com/prometheus/client_golang/prometheus/promhttp"
sctfe "github.com/transparency-dev/static-ct"
"github.com/transparency-dev/static-ct/storage"
awsSCTFE "github.com/transparency-dev/static-ct/storage/aws"
Expand All @@ -50,7 +49,6 @@ var (
notAfterLimit timestampFlag

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

metricsAt := *metricsEndpoint
if metricsAt == "" {
metricsAt = *httpEndpoint
}

if metricsAt != *httpEndpoint {
// Run a separate handler for metrics.
go func() {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
metricsServer := http.Server{Addr: metricsAt, Handler: mux}
err := metricsServer.ListenAndServe()
klog.Warningf("Metrics server exited: %v", err)
}()
} else {
// Handle metrics on the DefaultServeMux.
http.Handle("/metrics", promhttp.Handler())
}

// Bring up the HTTP server and serve until we get a signal not to.
srv := http.Server{Addr: *httpEndpoint}
shutdownWG := new(sync.WaitGroup)
Expand Down
25 changes: 4 additions & 21 deletions cmd/gcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"syscall"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
sctfe "github.com/transparency-dev/static-ct"
"github.com/transparency-dev/static-ct/storage"
gcpSCTFE "github.com/transparency-dev/static-ct/storage/gcp"
Expand All @@ -49,7 +48,6 @@ var (
notAfterLimit timestampFlag

httpEndpoint = flag.String("http_endpoint", "localhost:6962", "Endpoint for HTTP (host:port).")
metricsEndpoint = flag.String("metrics_endpoint", "", "Endpoint for serving metrics; if left empty, metrics will be visible on --http_endpoint.")
httpDeadline = flag.Duration("http_deadline", time.Second*10, "Deadline for HTTP requests.")
maskInternalErrors = flag.Bool("mask_internal_errors", false, "Don't return error strings with Internal Server Error HTTP responses.")
origin = flag.String("origin", "", "Origin of the log, for checkpoints and the monitoring prefix.")
Expand All @@ -63,6 +61,7 @@ var (
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.")
signerPublicKeySecretName = flag.String("signer_public_key_secret_name", "", "Public key secret name for checkpoints and SCTs signer. Format: projects/{projectId}/secrets/{secretName}/versions/{secretVersion}.")
signerPrivateKeySecretName = flag.String("signer_private_key_secret_name", "", "Private key secret name for checkpoints and SCTs signer. Format: projects/{projectId}/secrets/{secretName}/versions/{secretVersion}.")
traceFraction = flag.Float64("trace_fraction", 0, "Fraction of open-telemetry span traces to sample")
)

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

shutdownOTel := initOTel(ctx, *traceFraction)
defer shutdownOTel(ctx)

signer, err := NewSecretManagerSigner(ctx, *signerPublicKeySecretName, *signerPrivateKeySecretName)
if err != nil {
klog.Exitf("Can't create secret manager signer: %v", err)
Expand All @@ -95,25 +97,6 @@ func main() {
klog.Info("**** CT HTTP Server Starting ****")
http.Handle("/", logHandler)

metricsAt := *metricsEndpoint
if metricsAt == "" {
metricsAt = *httpEndpoint
}

if metricsAt != *httpEndpoint {
// Run a separate handler for metrics.
go func() {
mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler())
metricsServer := http.Server{Addr: metricsAt, Handler: mux}
err := metricsServer.ListenAndServe()
klog.Warningf("Metrics server exited: %v", err)
}()
} else {
// Handle metrics on the DefaultServeMux.
http.Handle("/metrics", promhttp.Handler())
}

// Bring up the HTTP server and serve until we get a signal not to.
srv := http.Server{Addr: *httpEndpoint}
shutdownWG := new(sync.WaitGroup)
Expand Down
75 changes: 75 additions & 0 deletions cmd/gcp/otel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright 2025 The Tessera 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 (
"context"
"errors"

"go.opentelemetry.io/otel"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
sdktrace "go.opentelemetry.io/otel/sdk/trace"

mexporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric"
texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
"k8s.io/klog/v2"
)

// initOTel initialises the open telemetry support for metrics and tracing.
//
// Tracing is enabled with statistical sampling, with the probability passed in.
// Returns a shutdown function which should be called just before exiting the process.
func initOTel(ctx context.Context, traceFraction float64) func(context.Context) {
var shutdownFuncs []func(context.Context) error
// shutdown combines shutdown functions from multiple OpenTelemetry
// components into a single function.
shutdown := func(ctx context.Context) {
var err error
for _, fn := range shutdownFuncs {
err = errors.Join(err, fn(ctx))
}
shutdownFuncs = nil
if err != nil {
klog.Errorf("OTel shutdown: %v", err)
}
}

me, err := mexporter.New()
if err != nil {
klog.Exitf("Failed to create metric exporter: %v", err)
return nil
}
// initialize a MeterProvider that periodically exports to the GCP exporter.
mp := sdkmetric.NewMeterProvider(
sdkmetric.WithReader(sdkmetric.NewPeriodicReader(me)),
)
shutdownFuncs = append(shutdownFuncs, mp.Shutdown)
otel.SetMeterProvider(mp)

te, err := texporter.New()
if err != nil {
klog.Exitf("Failed to create trace exporter: %v", err)
return nil
}
// initialize a TracerProvier that periodically exports to the GCP exporter.
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.TraceIDRatioBased(traceFraction)),
sdktrace.WithBatcher(te),
)
shutdownFuncs = append(shutdownFuncs, mp.Shutdown)
otel.SetTracerProvider(tp)

return shutdown
}
2 changes: 1 addition & 1 deletion ctlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func NewLogHandler(ctx context.Context, origin string, signer crypto.Signer, cfg
TimeSource: sysTimeSource,
}

handlers := scti.NewPathHandlers(opts, log)
handlers := scti.NewPathHandlers(ctx, opts, log)
mux := http.NewServeMux()
// Register handlers for all the configured logs.
for path, handler := range handlers {
Expand Down
27 changes: 11 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,32 @@ go 1.24.0

require (
cloud.google.com/go/secretmanager v1.14.6
cloud.google.com/go/spanner v1.78.0
cloud.google.com/go/spanner v1.79.0
cloud.google.com/go/storage v1.51.0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.27.0
github.com/RobinUS2/golang-moving-average v1.0.0
github.com/aws/aws-sdk-go-v2 v1.36.3
github.com/aws/aws-sdk-go-v2/config v1.29.13
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.1
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.35.3
github.com/aws/smithy-go v1.22.3
github.com/gdamore/tcell/v2 v2.8.1
github.com/go-sql-driver/mysql v1.9.1
github.com/go-sql-driver/mysql v1.9.2
github.com/google/go-cmp v0.7.0
github.com/kylelemons/godebug v1.1.0
github.com/prometheus/client_golang v1.21.1
github.com/rivo/tview v0.0.0-20240625185742-b0a7293b8130
github.com/transparency-dev/formats v0.0.0-20250127084410-134797944be6
github.com/transparency-dev/merkle v0.0.2
github.com/transparency-dev/trillian-tessera v0.1.2-0.20250320160837-ae724376e1ac
github.com/transparency-dev/trillian-tessera v0.1.2-0.20250408153912-a650aa01f2a4
go.etcd.io/bbolt v1.4.0
go.opentelemetry.io/otel v1.35.0
go.opentelemetry.io/otel/metric v1.35.0
go.opentelemetry.io/otel/sdk v1.35.0
go.opentelemetry.io/otel/sdk/metric v1.35.0
golang.org/x/crypto v0.37.0
golang.org/x/mod v0.24.0
golang.org/x/net v0.38.0
golang.org/x/net v0.39.0
google.golang.org/api v0.228.0
google.golang.org/grpc v1.71.1
k8s.io/klog/v2 v2.130.1
Expand All @@ -39,10 +44,10 @@ require (
cloud.google.com/go/iam v1.4.2 // indirect
cloud.google.com/go/longrunning v0.6.6 // indirect
cloud.google.com/go/monitoring v1.24.1 // indirect
cloud.google.com/go/trace v1.11.3 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/GoogleCloudPlatform/grpc-gcp-go/grpcgcp v1.5.2 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.27.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.51.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 // indirect
github.com/avast/retry-go/v4 v4.6.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect
Expand All @@ -59,7 +64,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.18 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cncf/xds/go v0.0.0-20250121191232-2f005788dc42 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
Expand All @@ -75,24 +79,15 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
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.1 // indirect
github.com/prometheus/common v0.62.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.35.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.59.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.59.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
golang.org/x/oauth2 v0.28.0 // indirect
Expand Down
Loading
Loading