Enabled metrics for apiserversource#1761
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sayanh The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @sayanh. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
626dc4e to
5ce5b0e
Compare
|
/ok-to-test |
|
Can you add in the release notes that the ApiServerSource now reports event counts |
| ) | ||
|
|
||
| const ( | ||
| component = "ApiServerSource::ReceiveAdapter" |
There was a problem hiding this comment.
can we just call it apiserversource? This will end up changing to be importer later on, but not right now as we need some other changes to be merged in
| // _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" | ||
|
|
||
| "knative.dev/eventing/pkg/reconciler/apiserversource/resources" | ||
|
|
There was a problem hiding this comment.
remove whitespace and run go importer formatting
| // Convert base64 encoded json logging.Config to logging.Config. | ||
| loggingConfig, err := resources.Base64ToLoggingConfig( | ||
| env.LoggingConfigBase64) | ||
| if err != nil { |
There was a problem hiding this comment.
Can we log an error, and try to use the default one. If it fails, then panic...
As here:
https://github.com/google/knative-gcp/blob/cabd0d258db1d23246d51fac8b181fd4c363c28e/cmd/pubsub/receive_adapter/main.go#L55
| metricsConfig, err := resources.Base64ToMetricsOptions( | ||
| env.MetricsConfigBase64) | ||
| if err != nil { | ||
| panic(err) |
There was a problem hiding this comment.
logger.Errorf("failed to process metrics options: %s", err.Error())
| panic(err) | ||
| } | ||
|
|
||
| logger, _ := logging.NewLoggerFromConfig(loggingConfig, component) |
There was a problem hiding this comment.
put this above the call to resources.Base64ToMetricsOptions
|
|
||
| package apiserver | ||
|
|
||
| // Type gets the eventtype. |
There was a problem hiding this comment.
update comment.
Can you add a TODO saying we should use HTTP status codes once this is merged: cloudevents/sdk-go#177
| return err | ||
| } | ||
| return nil | ||
| return a.sendEvent(context.Background(), event, a.reporter) |
There was a problem hiding this comment.
no need to pass the reporter as it's in the adapter already
| } | ||
|
|
||
| func (a *ref) addControllerWatch(gvr schema.GroupVersionResource) { | ||
| reportArgs := &ReportArgs{ |
| } | ||
| a.reporter.ReportEventCount(reportArgs, nil) | ||
|
|
||
| if _, err := a.ce.Send(ctx, *event); err != nil { |
There was a problem hiding this comment.
_, err := a.ce.Send(ctx, *event)
if err != nil {
a.logger.Info("event delivery failed", zap.Error(err))
}
a.reporter.ReportEventCount(reportArgs, err)
return err
| } | ||
| a.reporter.ReportEventCount(reportArgs, nil) | ||
|
|
||
| if _, err := a.ce.Send(ctx, *event); err != nil { |
There was a problem hiding this comment.
same as previous comment
|
|
||
| var ( | ||
| // eventCountM is a counter which records the number of events received | ||
| // by a Trigger. |
There was a problem hiding this comment.
update comment: .... number of events sent by an Importer
| eventTypeKey tag.Key | ||
| eventSourceKey tag.Key | ||
| resultKey tag.Key | ||
| filterResultKey tag.Key |
| filterResultKey tag.Key | ||
| } | ||
|
|
||
| // NewStatsReporter creates a reporter that collects and reports filter metrics. |
There was a problem hiding this comment.
NewStatsReporter creates a reporter that collects and reports apiserversource metrics.
| return nil, err | ||
| } | ||
| r.eventSourceKey = eventSourceTag | ||
| filterResultTag, err := tag.NewKey(metricskey.FilterResult) |
| &view.View{ | ||
| Description: eventCountM.Description(), | ||
| Measure: eventCountM, | ||
| // TODO count or sum aggregation? |
| return tag.New( | ||
| context.Background(), | ||
| tag.Insert(r.namespaceTagKey, args.ns), | ||
| tag.Insert(r.eventSourceKey, valueOrAny(args.eventSource)), |
There was a problem hiding this comment.
we do not need valueOrAny here. As they will not be empty... Can you remove that, and also the note?
| } | ||
|
|
||
| wantTags1 := map[string]string(wantTags) | ||
| wantTags1[metricskey.Result] = "success" |
There was a problem hiding this comment.
this should be part of the wantTags, right? No need for a wantTags1
|
|
||
| } | ||
|
|
||
| func TestReporterEmptySourceAndType(t *testing.T) { |
There was a problem hiding this comment.
this one will never happen as we are setting up the event source and type in the CloudEvent, otherwise it's not a valid CloudEvent.
It should be fine to remove, or maybe change it to test for the error condition... pass an error to ReportEventCount and see that instead of success you have the error label
There was a problem hiding this comment.
Added a new test for now TestReporterForErrorTag
| EventType = "event_type" | ||
|
|
||
| // EventSource is the label for the CloudEvents source context attribute. | ||
| EventSource = "event_source" |
There was a problem hiding this comment.
all these constants are in knative.dev/pkg/metrics/metricskey now, as LabelEventSource, etc. Can we use those instead? I'll make the changes in the other places, and remove these constants
| @@ -0,0 +1,134 @@ | |||
| /* | |||
There was a problem hiding this comment.
it would be nice to move this down to pkg as we are going to use it in many places.
@n3wscott what do you think?
There was a problem hiding this comment.
How about pkg/utils?
| } | ||
|
|
||
| func (a *ref) sendEvent(ctx context.Context, event *cloudevents.Event, reporter StatsReporter) error { | ||
| reportArgs := &ReportArgs{ |
There was a problem hiding this comment.
We will also need to add the importerName and the importerResourceGroup... So that we can also filter based on those attributes. E.g., give me the event_count of all apiserversource importers, and so on...
The name you might need to send it in an env variable to the receive_adapter (as we do in the broker ingress)...
The importerResourceGroup can be hardcoded to apiserversources.sources.eventing.knative.dev (put it in a constant)
See labels for tags here: https://github.com/knative/pkg/blob/ec2f20ae67fbbccfac425061f2c7c089d1932105/metrics/metricskey/constants_eventing.go#L52-54
There was a problem hiding this comment.
Added those tags now. A sample metrics looks like:
apiserversource_event_count{event_source="https://1.2.3.4:443",event_type="dev.knative.apiserver.resource.update",importer_name="testevents",importer_resource_group="apiserversources.sources.eventing.knative.dev",namespace_name="default"} 3
9b50089 to
0f3b53d
Compare
|
The following is the coverage report on pkg/.
|
|
@sayanh: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
|
Closing this as this is a duplicate for #1786 |
Helps #1693
Proposed Changes
Release Note