Skip to content

Commit

Permalink
make eventing metrics generic (#5478)
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto authored Jun 8, 2021
1 parent db83525 commit b05d993
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
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

0 comments on commit b05d993

Please sign in to comment.