Skip to content
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

feat: allow controlling of StartCall info logging from a service runtime #422

Merged
merged 1 commit into from
Oct 8, 2024
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
6 changes: 3 additions & 3 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var httpCallLatency = promauto.NewHistogramVec( // nolint:gochecknoglobals // Wh
Help: "The latency of the HTTP request, in seconds",
Buckets: prometheus.DefBuckets,
},
[]string{"app", "call", "statuscode", "statuscategory", "kind"}, // Labels
[]string{"target", "call", "statuscode", "statuscategory", "kind"}, // Labels

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jan-ludvik I think we've found why we get two app names separated by comma, if we're right -- this PR will fix the issue. FYI.

)

// ReportHTTPLatency reports the http_request_handled metric for a request.
Expand Down Expand Up @@ -90,7 +90,7 @@ var grpcCallLatency = promauto.NewHistogramVec( // nolint:gochecknoglobals // Wh
Help: "The latency of the gRPC request, in seconds",
Buckets: prometheus.DefBuckets,
},
[]string{"app", "call", "statuscode", "statuscategory", "kind"}, // Labels
[]string{"target", "call", "statuscode", "statuscategory", "kind"}, // Labels
)

// ReportGRPCLatency reports the grpc_request_handled metric for a request.
Expand Down Expand Up @@ -121,7 +121,7 @@ var outboundCallLatency = promauto.NewHistogramVec( // nolint:gochecknoglobals /
Help: "The latency of the outbound request, in seconds",
Buckets: prometheus.DefBuckets,
},
[]string{"app", "call", "statuscode", "statuscategory", "kind"}, // Labels
[]string{"target", "call", "statuscode", "statuscategory", "kind"}, // Labels
)

// ReportOutboundLatency reports the outbound_call_seconds metric for a request.
Expand Down
14 changes: 13 additions & 1 deletion pkg/trace/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,19 @@ func SetCustomCallKind(ctx context.Context, ck metrics.CallKind) {
// GetCallName returns name of the current call
func GetCallName(ctx context.Context) string {
info := callTracker.Info(ctx)
return info.Name
if info != nil {
return info.Name
}
return ""
}

// IsInfoLoggingEnabled returns state of info logging
func IsInfoLoggingEnabled(ctx context.Context) bool {
info := callTracker.Info(ctx)
if info != nil {
return info.Opts.EnableInfoLogging
}
return false
}

// EndCall calculates the duration of the call, writes to metrics,
Expand Down
2 changes: 1 addition & 1 deletion pkg/trace/call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ func TestReportLatencyMetrics(t *testing.T) {
}, protocmp.Transform()))

assert.Check(t, cmp.Equal(metric.GetLabel(), []*dto.LabelPair{
{Name: proto.String("app"), Value: proto.String("gobox")},
{Name: proto.String("call"), Value: proto.String("test")},
{Name: proto.String("kind"), Value: proto.String("internal")},
{Name: proto.String("statuscategory"), Value: proto.String("CategoryOK")},
{Name: proto.String("statuscode"), Value: proto.String("OK")},
{Name: proto.String("target"), Value: proto.String("gobox")},
}, protocmp.Transform()))
}

Expand Down
41 changes: 41 additions & 0 deletions pkg/trace/resolver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2023 Outreach Corporation. All Rights Reserved.

// Description: This file contains constants and tools for controlling trace.Start/EndCall logging

package trace

import (
"context"

"github.com/getoutreach/gobox/pkg/log"
)

type InfoLoggingResolved int32

const (
InfoLoggingDefault InfoLoggingResolved = 0
InfoLoggingEnabled InfoLoggingResolved = 1
InfoLoggingDisabled InfoLoggingResolved = 2
)

type InfoLoggingResolver = func(ctx context.Context, operation string) InfoLoggingResolved

// ResolvedLogging returns signals trace.EndCall whether to enable/disable info logging
func ResolvedLogging(logging InfoLoggingResolved) log.Marshaler {
if logging == InfoLoggingDefault {
return nil
}
if logging == InfoLoggingEnabled {
return WithInfoLoggingEnabled()
}
return WithInfoLoggingDisabled()
}

func ReevaluateLogging(ctx context.Context, resolver InfoLoggingResolver) {
logging := resolver(ctx, GetCallName(ctx))
if logging == InfoLoggingDefault {
return
}
callInfo := callTracker.Info(ctx)
callInfo.Opts.EnableInfoLogging = logging == InfoLoggingEnabled
}
Loading