MCPcopy
hub / github.com/grafana/dskit / HandleRPC

Method HandleRPC

server/limits.go:155–185  ·  view source on GitHub ↗
(ctx context.Context, rpcStats stats.RPCStats)

Source from the content-addressed store, hash-verified

153}
154
155func (g *grpcInflightLimitCheck) HandleRPC(ctx context.Context, rpcStats stats.RPCStats) {
156 switch rpcStats.(type) {
157 case *stats.InHeader:
158 if state, ok := ctx.Value(gprcInflightLimitCheckerStateKey{}).(*gprcInflightLimitCheckerState); ok {
159 // We're processing this request, stop the timer.
160 if !state.nonProcessedRequestTimer.Stop() {
161 level.Warn(state.logger(g.logger)).Log("msg", "gRPC request processing has started, but the non-processing timer already fired, need to signal that we're processing it now")
162 // The timer has already expired, so the function is either executing or has executed.
163 //
164 // This (stats.InHeader) should be called once and only once, but gRPC is known for changing contracts
165 // and we don't want this to start panicking trying to close the channel multiple times,
166 // so a sync.Once doesn't hurt here.
167 state.headersProcessedOnce.Do(func() { close(state.headersProcessed) })
168 }
169 }
170
171 case *stats.End:
172 if state, ok := ctx.Value(gprcInflightLimitCheckerStateKey{}).(*gprcInflightLimitCheckerState); ok {
173 // We're done processing the request, but there's a scenario under which we may have already called RPCCallFinished,
174 // from the goroutine watching the context in TapHandle, so we need to ensure it's called only once.
175 called := false
176 state.rpcCallFinishedOnce.Do(func() {
177 g.methodLimiter.RPCCallFinished(ctx)
178 called = true
179 })
180 if !called {
181 level.Warn(state.logger(g.logger)).Log("msg", "RPCCallFinished was already called for this gRPC request before the request actually finished processing")
182 }
183 }
184 }
185}
186
187func (g *grpcInflightLimitCheck) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context {
188 return ctx

Callers

nothing calls this directly

Calls 5

loggerMethod · 0.80
StopMethod · 0.65
RPCCallFinishedMethod · 0.65
LogMethod · 0.45
DoMethod · 0.45

Tested by

no test coverage detected