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

Make eventing channel metrics generic enough to be used by other impl #5478

Merged
merged 1 commit into from
Jun 8, 2021
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
7 changes: 4 additions & 3 deletions pkg/channel/fanout/fanout_message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func createMessageReceiverFunction(f *FanoutMessageHandler) func(context.Context
ctx = trace.NewContext(context.Background(), s)
// Any returned error is already logged in f.dispatch().
dispatchResultForFanout := f.dispatch(ctx, subs, m, h)
_ = parseFanoutResultAndReportMetrics(dispatchResultForFanout, *r, *args)
_ = ParseDispatchResultAndReportMetrics(dispatchResultForFanout, *r, *args)
}(bufferedMessage, additionalHeaders, parentSpan, &f.reporter, &reportArgs)
return nil
}
Expand All @@ -217,15 +217,16 @@ func createMessageReceiverFunction(f *FanoutMessageHandler) func(context.Context
reportArgs.EventType = string(te)
reportArgs.Ns = ref.Namespace
dispatchResultForFanout := f.dispatch(ctx, subs, bufferedMessage, additionalHeaders)
return parseFanoutResultAndReportMetrics(dispatchResultForFanout, f.reporter, reportArgs)
return ParseDispatchResultAndReportMetrics(dispatchResultForFanout, f.reporter, reportArgs)
}
}

func (f *FanoutMessageHandler) ServeHTTP(response nethttp.ResponseWriter, request *nethttp.Request) {
f.receiver.ServeHTTP(response, request)
}

func parseFanoutResultAndReportMetrics(result dispatchResult, reporter channel.StatsReporter, reportArgs channel.ReportArgs) error {
// ParseDispatchResultAndReportMetric processes the dispatch result and records the related channel metrics with the appropriate context
func ParseDispatchResultAndReportMetrics(result dispatchResult, reporter channel.StatsReporter, reportArgs channel.ReportArgs) error {
if result.info != nil && result.info.Time > channel.NoDuration {
if result.info.ResponseCode > channel.NoResponse {
_ = reporter.ReportEventDispatchTime(&reportArgs, result.info.ResponseCode, result.info.Time)
Expand Down
12 changes: 6 additions & 6 deletions pkg/channel/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ import (
)

var (
// eventCountM is a counter which records the number of events received
// by the in-memory Channel.
// eventCountM is a counter which records the number of events dispatched
// by the channel.
eventCountM = stats.Int64(
"event_count",
"Number of events dispatched by the in-memory channel",
"Number of events dispatched by the channel",
stats.UnitDimensionless,
)

// dispatchTimeInMsecM records the Time spent dispatching an event to
// a Channel, in milliseconds.
// dispatchTimeInMsecM records the time spent by the channel dispatching an event to
// to subscribers, in milliseconds.
dispatchTimeInMsecM = stats.Float64(
"event_dispatch_latencies",
"The Time spent dispatching an event from a in-memoryChannel",
"The time spent by the channel dispatching an event",
stats.UnitMilliseconds,
)

Expand Down