Skip to content

Commit

Permalink
Remove unused aws-sdk-go S3 metrics wrapper (#51674)
Browse files Browse the repository at this point in the history
The wrapper is no longer used since all S3 code has been converted
to use aws-sdk-go-v2.
  • Loading branch information
rosstimothy authored Jan 30, 2025
1 parent f2401d5 commit 2f9bd2a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 95 deletions.
6 changes: 5 additions & 1 deletion lib/events/s3sessions/s3handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/gravitational/teleport/lib/events"
"github.com/gravitational/teleport/lib/modules"
awsmetrics "github.com/gravitational/teleport/lib/observability/metrics/aws"
s3metrics "github.com/gravitational/teleport/lib/observability/metrics/s3"
"github.com/gravitational/teleport/lib/session"
awsutils "github.com/gravitational/teleport/lib/utils/aws"
"github.com/gravitational/teleport/lib/utils/aws/endpoint"
Expand Down Expand Up @@ -197,7 +198,10 @@ func NewHandler(ctx context.Context, cfg Config) (*Handler, error) {
opts = append(opts, config.WithCredentialsProvider(cfg.CredentialsProvider))
}

opts = append(opts, config.WithAPIOptions(awsmetrics.MetricsMiddleware()))
opts = append(opts,
config.WithAPIOptions(awsmetrics.MetricsMiddleware()),
config.WithAPIOptions(s3metrics.MetricsMiddleware()),
)

resolver, err := endpoint.NewLoggingResolver(
s3.NewDefaultEndpointResolverV2(),
Expand Down
74 changes: 0 additions & 74 deletions lib/observability/metrics/s3/manager.go

This file was deleted.

27 changes: 7 additions & 20 deletions lib/observability/metrics/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
"github.com/aws/smithy-go/middleware"
"github.com/prometheus/client_golang/prometheus"

"github.com/gravitational/teleport/lib/observability/metrics"
)

var (
Expand Down Expand Up @@ -52,24 +54,10 @@ var (
},
[]string{"operation"},
)

s3Collectors = []prometheus.Collector{
apiRequestsTotal,
apiRequests,
apiRequestLatencies,
}
)

// recordMetrics updates the set of s3 api metrics
func recordMetrics(operation string, err error, latency float64) {
apiRequestLatencies.WithLabelValues(operation).Observe(latency)
apiRequestsTotal.WithLabelValues(operation).Inc()

result := "success"
if err != nil {
result = "error"
}
apiRequests.WithLabelValues(operation, result).Inc()
func init() {
_ = metrics.RegisterPrometheusCollectors(apiRequests, apiRequestsTotal, apiRequestLatencies)
}

// MetricsMiddleware returns middleware that can be used to capture
Expand Down Expand Up @@ -97,13 +85,12 @@ func MetricsMiddleware() []func(stack *middleware.Stack) error {
}

then := ctx.Value(timestampKey{}).(time.Time)
service := awsmiddleware.GetServiceID(ctx)
operation := awsmiddleware.GetOperationName(ctx)
latency := time.Since(then).Seconds()

apiRequestsTotal.WithLabelValues(service, operation).Inc()
apiRequestLatencies.WithLabelValues(service, operation).Observe(latency)
apiRequests.WithLabelValues(service, operation, result).Inc()
apiRequestsTotal.WithLabelValues(operation).Inc()
apiRequestLatencies.WithLabelValues(operation).Observe(latency)
apiRequests.WithLabelValues(operation, result).Inc()

return out, md, err
}), middleware.After)
Expand Down

0 comments on commit 2f9bd2a

Please sign in to comment.