Skip to content

Commit

Permalink
Adding mTLS support for Otel and removing logger for trace service
Browse files Browse the repository at this point in the history
  • Loading branch information
ssunka committed Sep 27, 2024
1 parent 2fedab2 commit a2cc470
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
13 changes: 5 additions & 8 deletions src/internal/nozzle/otel_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/cloudfoundry/metric-store-release/src/pkg/logger"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

type OtelServer struct {
Expand Down Expand Up @@ -55,15 +54,14 @@ func (s *OtelServer) Start(addr string, otelTlsConfig *tls.Config) {
s.log.Info("OtelServer starting grpc server at ", zap.String("address", addr))

// Initialize gRPC server with TLS credentials
grpcServer := grpc.NewServer(grpc.Creds(credentials.NewTLS(otelTlsConfig)))
grpcServer := grpc.NewServer()
// Start the gRPC server in a separate goroutine
go s.startGRPCServer(addr, grpcServer, otelTlsConfig)

// Register Metric and Trace services with the gRPC server
metricspb.RegisterMetricsServiceServer(grpcServer, s.ms)
tracepb.RegisterTraceServiceServer(grpcServer, s.ts)

// Start the gRPC server in a separate goroutine
go s.startGRPCServer(addr, grpcServer)

s.log.Info("Starting Metrics and Trace Servers")
s.ms.StartListening()
s.ts.StartListening()
Expand All @@ -89,7 +87,7 @@ func NewOtelServer(
}

// StartGRPCServer starts the gRPC server and listens for incoming connections.
func (s *OtelServer) startGRPCServer(addr string, grpcServer *grpc.Server) {
func (s *OtelServer) startGRPCServer(addr string, grpcServer *grpc.Server, otelTlsConfig *tls.Config) {
defer func() {
close(s.done)
}()
Expand All @@ -99,8 +97,7 @@ func (s *OtelServer) startGRPCServer(addr string, grpcServer *grpc.Server) {
if err != nil {
s.log.Panic("Failed to resolve address", zap.Error(err))
}

listener, err := net.ListenTCP("tcp", resolvedAddr)
listener, err := tls.Listen("tcp", resolvedAddr.String(), otelTlsConfig)
if err != nil {
s.log.Panic("Failed to start listener", zap.Error(err))
}
Expand Down
7 changes: 3 additions & 4 deletions src/internal/nozzle/trace_service.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package nozzle

import (
"strconv"
"time"

"code.cloudfoundry.org/go-diodes"
"github.com/cloudfoundry/metric-store-release/src/internal/metrics"
"github.com/cloudfoundry/metric-store-release/src/internal/nozzle/rollup"
"github.com/cloudfoundry/metric-store-release/src/pkg/logger"
"github.com/cloudfoundry/metric-store-release/src/pkg/persistence/transform"
"strconv"
"time"

"github.com/cloudfoundry/metric-store-release/src/pkg/ingressclient"
"github.com/cloudfoundry/metric-store-release/src/pkg/rpc"
Expand Down Expand Up @@ -159,8 +160,6 @@ func (s *TraceService) convertToSpan(sp *ot.Span) *rpc.Span {
}

func (s *TraceService) addToRollup(span *rpc.Span) {
s.log.Log("msg", "TraceService.addToRollup:", "span", span)

s.totalRollup.Record(span.SourceId, span.Labels, 1)
s.durationRollup.Record(span.SourceId, span.Labels, span.Duration)
}
Expand Down

0 comments on commit a2cc470

Please sign in to comment.