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

stats/opentelemetry: separate out interceptors for tracing and metrics #8063

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

janardhanvissa
Copy link
Contributor

@janardhanvissa janardhanvissa commented Feb 3, 2025

RELEASE NOTE: None

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 84.15842% with 16 lines in your changes missing coverage. Please review.

Project coverage is 82.38%. Comparing base (39f0e5a) to head (50999a0).
Report is 29 commits behind head on master.

Files with missing lines Patch % Lines
stats/opentelemetry/client_metrics.go 79.31% 10 Missing and 2 partials ⚠️
stats/opentelemetry/server_metrics.go 80.95% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8063      +/-   ##
==========================================
+ Coverage   82.27%   82.38%   +0.10%     
==========================================
  Files         386      387       +1     
  Lines       39038    39027      -11     
==========================================
+ Hits        32120    32152      +32     
+ Misses       5590     5569      -21     
+ Partials     1328     1306      -22     
Files with missing lines Coverage Δ
stats/opentelemetry/opentelemetry.go 77.90% <100.00%> (+2.90%) ⬆️
stats/opentelemetry/server_metrics.go 88.20% <80.95%> (-1.62%) ⬇️
stats/opentelemetry/client_metrics.go 85.46% <79.31%> (-3.94%) ⬇️

... and 53 files with indirect coverage changes

@janardhanvissa janardhanvissa force-pushed the refactor-tracing-metrics branch from 69df069 to 71804b4 Compare February 3, 2025 11:48
@purnesh42H
Copy link
Contributor

@janardhanvissa its not clear what is the intention of this refactor. The follow up from opentelemetry tracing API PR was to create separate interceptors for metrics and traces. Right now, single interceptor is handling both trace and metrics options. Once we have separate unary and stream interceptor each for tracing and metrics, we don't have to check for options disabled/enabled everytime.

Copy link
Contributor

@purnesh42H purnesh42H left a comment

Choose a reason for hiding this comment

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

Please see this discussion https://github.com/grpc/grpc-go/pull/7852/files#r1909469701 and modify accordingly.

@purnesh42H purnesh42H changed the title opentelemetry: Refactor tracing and metrics separately stats/opentelemetry: separate out interceptors for tracing and metrics Feb 19, 2025
type clientMetricsStatsHandler struct {
*clientStatsHandler
}
type clientTracingStatsHandler struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

new line in between struct declaration

method: h.determineMethod(method, opts...),
}
ctx = setCallInfo(ctx, ci)
if h.options.MetricsOptions.pluginOption != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

this metadata part is not applicable for tracing. It should only be in metrics interceptor. Please remove

}
ctx = setCallInfo(ctx, ci)

if h.options.MetricsOptions.pluginOption != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

same. this metadata part is not applicable for tracing. It should only be in metrics interceptor. Please remove

}

// perCallTraces records per call trace spans.
func (h *clientTracingStatsHandler) perCallTraces(_ context.Context, err error, _ time.Time, _ *callInfo, ts trace.Span) {
Copy link
Contributor

Choose a reason for hiding this comment

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

since we don't need time and callInfo, we should not just have them here instead of replacing them with _

@@ -120,7 +120,17 @@ type MetricsOptions struct {
func DialOption(o Options) grpc.DialOption {
csh := &clientStatsHandler{options: o}
csh.initializeMetrics()
return joinDialOptions(grpc.WithChainUnaryInterceptor(csh.unaryInterceptor), grpc.WithChainStreamInterceptor(csh.streamInterceptor), grpc.WithStatsHandler(csh))
var interceptors []grpc.DialOption
if o.isMetricsEnabled() {
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think we need to check anything here. We should just always add all the 4 interceptors. We should have initializeMetrics and initialTraces methods of respective stats handler that check and return early if they are not enabled.

Currently, initializeMetrics exist in statsHandler for server and client which does that. We should modify it to be part of metricsStatsHandler and create the similar function for traceStatsHandler

@@ -140,7 +150,17 @@ var joinServerOptions = internal.JoinServerOptions.(func(...grpc.ServerOption) g
func ServerOption(o Options) grpc.ServerOption {
ssh := &serverStatsHandler{options: o}
ssh.initializeMetrics()
return joinServerOptions(grpc.ChainUnaryInterceptor(ssh.unaryInterceptor), grpc.ChainStreamInterceptor(ssh.streamInterceptor), grpc.StatsHandler(ssh))
var interceptors []grpc.ServerOption
if o.isMetricsEnabled() {
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as dial option

@@ -211,24 +218,41 @@ func (h *serverStatsHandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo)

// HandleRPC implements per RPC tracing and stats implementation.
func (h *serverStatsHandler) HandleRPC(ctx context.Context, rs stats.RPCStats) {
if h.options.isMetricsEnabled() {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should have separate HandleRPC for metrics and trace statsHandlers instead of having common which requires to check what is enabled etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants