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

Eventing TLS: Add scheme label to metrics #7581

Merged
merged 19 commits into from
Jan 22, 2024
1 change: 1 addition & 0 deletions pkg/adapter/v2/cloudevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func (c *client) reportMetrics(ctx context.Context, event cloudevents.Event, res
EventType: event.Type(),
Name: tags.Name,
ResourceGroup: tags.ResourceGroup,
EventScheme: event.Scheme(),
}

var rres *http.RetriesResult
Expand Down
3 changes: 3 additions & 0 deletions pkg/broker/filter/filter_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func (h *Handler) handleDispatchToReplyRequest(ctx context.Context, trigger *eve
trigger: trigger.Name,
broker: trigger.Spec.Broker,
requestType: "reply_forward",
requestScheme: request.URL.Scheme,
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
}

h.logger.Info("sending to reply", zap.Any("target", target))
Expand Down Expand Up @@ -275,6 +276,7 @@ func (h *Handler) handleDispatchToDLSRequest(ctx context.Context, trigger *event
trigger: trigger.Name,
broker: trigger.Spec.Broker,
requestType: "dls_forward",
requestScheme: request.URL.Scheme,
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
}

h.logger.Info("sending to dls", zap.Any("target", target))
Expand Down Expand Up @@ -310,6 +312,7 @@ func (h *Handler) handleDispatchToSubscriberRequest(ctx context.Context, trigger
broker: trigger.Spec.Broker,
filterType: triggerFilterAttribute(trigger.Spec.Filter, "type"),
requestType: "filter",
requestScheme: request.URL.Scheme,
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
}

subscriberURI := trigger.Status.SubscriberURI
Expand Down
27 changes: 15 additions & 12 deletions pkg/broker/filter/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,20 @@ var (
// go.opencensus.io/tag/validate.go. Currently those restrictions are:
// - length between 1 and 255 inclusive
// - characters are printable US-ASCII
triggerFilterTypeKey = tag.MustNewKey(eventingmetrics.LabelFilterType)
triggerFilterRequestTypeKey = tag.MustNewKey("filter_request_type")
responseCodeKey = tag.MustNewKey(eventingmetrics.LabelResponseCode)
responseCodeClassKey = tag.MustNewKey(eventingmetrics.LabelResponseCodeClass)
triggerFilterTypeKey = tag.MustNewKey(eventingmetrics.LabelFilterType)
triggerFilterRequestTypeKey = tag.MustNewKey("filter_request_type")
triggerFilterRequestSchemeKey = tag.MustNewKey(eventingmetrics.LabelEventScheme)
responseCodeKey = tag.MustNewKey(eventingmetrics.LabelResponseCode)
responseCodeClassKey = tag.MustNewKey(eventingmetrics.LabelResponseCodeClass)
)

type ReportArgs struct {
ns string
trigger string
broker string
filterType string
requestType string
ns string
trigger string
broker string
filterType string
requestType string
requestScheme string
}

func init() {
Expand Down Expand Up @@ -116,19 +118,19 @@ func register() {
Description: eventCountM.Description(),
Measure: eventCountM,
Aggregation: view.Count(),
TagKeys: []tag.Key{triggerFilterTypeKey, triggerFilterRequestTypeKey, responseCodeKey, responseCodeClassKey, broker.UniqueTagKey, broker.ContainerTagKey},
TagKeys: []tag.Key{triggerFilterTypeKey, triggerFilterRequestTypeKey, triggerFilterRequestSchemeKey, responseCodeKey, responseCodeClassKey, broker.UniqueTagKey, broker.ContainerTagKey},
},
&view.View{
Description: dispatchTimeInMsecM.Description(),
Measure: dispatchTimeInMsecM,
Aggregation: view.Distribution(metrics.Buckets125(1, 10000)...), // 1, 2, 5, 10, 20, 50, 100, 1000, 5000, 10000
TagKeys: []tag.Key{triggerFilterTypeKey, triggerFilterRequestTypeKey, responseCodeKey, responseCodeClassKey, broker.UniqueTagKey, broker.ContainerTagKey},
TagKeys: []tag.Key{triggerFilterTypeKey, triggerFilterRequestTypeKey, triggerFilterRequestSchemeKey, responseCodeKey, responseCodeClassKey, broker.UniqueTagKey, broker.ContainerTagKey},
},
&view.View{
Description: processingTimeInMsecM.Description(),
Measure: processingTimeInMsecM,
Aggregation: view.Distribution(metrics.Buckets125(1, 10000)...), // 1, 2, 5, 10, 20, 50, 100, 1000, 5000, 10000
TagKeys: []tag.Key{triggerFilterTypeKey, triggerFilterRequestTypeKey, broker.UniqueTagKey, broker.ContainerTagKey},
TagKeys: []tag.Key{triggerFilterTypeKey, triggerFilterRequestTypeKey, triggerFilterRequestSchemeKey, broker.UniqueTagKey, broker.ContainerTagKey},
},
)
if err != nil {
Expand Down Expand Up @@ -190,6 +192,7 @@ func (r *reporter) generateTag(args *ReportArgs, tags ...tag.Mutator) (context.C
tag.Insert(broker.UniqueTagKey, r.uniqueName),
tag.Insert(triggerFilterTypeKey, valueOrAny(args.filterType)),
tag.Insert(triggerFilterRequestTypeKey, args.requestType),
tag.Insert(triggerFilterRequestSchemeKey, args.requestScheme),
)...)
return ctx, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/broker/filter/stats_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func TestReporterEmptySourceAndTypeFilter(t *testing.T) {
trigger: "testtrigger",
broker: "testbroker",
filterType: "",
requestScheme: "http",
}

r := NewStatsReporter("testcontainer", "testpod")
Expand All @@ -110,6 +111,7 @@ func TestReporterEmptySourceAndTypeFilter(t *testing.T) {
metrics.LabelResponseCodeClass: "2xx",
broker.LabelContainerName: "testcontainer",
broker.LabelUniqueName: "testpod",
metrics.LabelEventScheme: "http",
}

resource := resource.Resource{
Expand Down
1 change: 1 addition & 0 deletions pkg/broker/ingress/ingress_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
ns: brokerNamespace,
broker: brokerName,
eventType: event.Type(),
eventScheme: event.Scheme(),
}

statusCode, dispatchTime := h.receive(ctx, utils.PassThroughHeaders(request.Header), event, broker)
Expand Down
13 changes: 9 additions & 4 deletions pkg/broker/ingress/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ var (
// - length between 1 and 255 inclusive
// - characters are printable US-ASCII
eventTypeKey = tag.MustNewKey(eventingmetrics.LabelEventType)
eventSchemKey = tag.MustNewKey(eventingmetrics.LabelEventScheme)
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
responseCodeKey = tag.MustNewKey(eventingmetrics.LabelResponseCode)
responseCodeClassKey = tag.MustNewKey(eventingmetrics.LabelResponseCodeClass)
)

type ReportArgs struct {
ns string
broker string
eventType string
ns string
broker string
eventType string
eventScheme string
}

func init() {
Expand Down Expand Up @@ -95,10 +97,12 @@ func NewStatsReporter(container, uniqueName string) StatsReporter {
func register() {
tagKeys := []tag.Key{
eventTypeKey,
eventSchemKey,
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
responseCodeKey,
responseCodeClassKey,
broker.ContainerTagKey,
broker.UniqueTagKey}
broker.UniqueTagKey,
}

// Create view to see our measurements.
err := metrics.RegisterResourceView(
Expand Down Expand Up @@ -154,6 +158,7 @@ func (r *reporter) generateTag(args *ReportArgs, responseCode int) (context.Cont
tag.Insert(broker.ContainerTagKey, r.container),
tag.Insert(broker.UniqueTagKey, r.uniqueName),
tag.Insert(eventTypeKey, args.eventType),
tag.Insert(eventSchemKey, args.eventScheme),
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
tag.Insert(responseCodeKey, strconv.Itoa(responseCode)),
tag.Insert(responseCodeClassKey, metrics.ResponseCodeClass(responseCode)))
}
2 changes: 2 additions & 0 deletions pkg/broker/ingress/stats_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestStatsReporter(t *testing.T) {
ns: "testns",
broker: "testbroker",
eventType: "testeventtype",
eventScheme: "http",
}

r := NewStatsReporter("testcontainer", "testpod")
Expand All @@ -45,6 +46,7 @@ func TestStatsReporter(t *testing.T) {
metrics.LabelResponseCodeClass: "2xx",
broker.LabelUniqueName: "testpod",
broker.LabelContainerName: "testcontainer",
metrics.LabelEventScheme: "http",
}

resource := resource.Resource{
Expand Down
8 changes: 6 additions & 2 deletions pkg/channel/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ var (
// - characters are printable US-ASCII
namespaceKey = tag.MustNewKey(eventingmetrics.LabelNamespaceName)
eventTypeKey = tag.MustNewKey(eventingmetrics.LabelEventType)
eventScheme = tag.MustNewKey(eventingmetrics.LabelEventScheme)
responseCodeKey = tag.MustNewKey(eventingmetrics.LabelResponseCode)
responseCodeClassKey = tag.MustNewKey(eventingmetrics.LabelResponseCodeClass)
)

type ReportArgs struct {
Ns string
EventType string
Ns string
EventType string
EventScheme string
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
}

func init() {
Expand Down Expand Up @@ -93,6 +95,7 @@ func register() {
tagKeys := []tag.Key{
namespaceKey,
eventTypeKey,
eventScheme,
responseCodeKey,
responseCodeClassKey,
UniqueTagKey,
Expand Down Expand Up @@ -145,6 +148,7 @@ func (r *reporter) generateTag(args *ReportArgs, responseCode int) (context.Cont
emptyContext,
tag.Insert(namespaceKey, args.Ns),
tag.Insert(eventTypeKey, args.EventType),
tag.Insert(eventScheme, args.EventScheme),
tag.Insert(responseCodeKey, strconv.Itoa(responseCode)),
tag.Insert(responseCodeClassKey, metrics.ResponseCodeClass(responseCode)),
tag.Insert(ContainerTagKey, r.container),
Expand Down
6 changes: 4 additions & 2 deletions pkg/channel/stats_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import (
func TestStatsReporter(t *testing.T) {
setup()
args := &ReportArgs{
Ns: "testns",
EventType: "testeventtype",
Ns: "testns",
EventType: "testeventtype",
EventScheme: "http",
}

r := NewStatsReporter("testcontainer", "testpod")
Expand All @@ -42,6 +43,7 @@ func TestStatsReporter(t *testing.T) {
metrics.LabelResponseCodeClass: "2xx",
LabelUniqueName: "testpod",
LabelContainerName: "testcontainer",
metrics.LabelEventScheme: "http",
}

// test ReportEventCount
Expand Down
3 changes: 3 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const (
// LabelEventType is the label for the name of the event type.
LabelEventType = "event_type"

// LabelEventType is the label for the name of the event type.
LabelEventScheme = "event_scheme"

// LabelEventSource is the label for the name of the event source.
LabelEventSource = "event_source"

Expand Down
7 changes: 6 additions & 1 deletion pkg/metrics/source/stats_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
namespaceKey = tag.MustNewKey(eventingmetrics.LabelNamespaceName)
eventSourceKey = tag.MustNewKey(eventingmetrics.LabelEventSource)
eventTypeKey = tag.MustNewKey(eventingmetrics.LabelEventType)
eventScheme = tag.MustNewKey(eventingmetrics.LabelEventScheme)
sourceNameKey = tag.MustNewKey(eventingmetrics.LabelName)
sourceResourceGroupKey = tag.MustNewKey(eventingmetrics.LabelResourceGroup)
responseCodeKey = tag.MustNewKey(eventingmetrics.LabelResponseCode)
Expand All @@ -62,6 +63,7 @@ var (
type ReportArgs struct {
Namespace string
EventType string
EventScheme string
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
EventSource string
Name string
ResourceGroup string
Expand Down Expand Up @@ -122,6 +124,7 @@ func (r *reporter) generateTag(args *ReportArgs, responseCode int) (context.Cont
tag.Insert(namespaceKey, args.Namespace),
tag.Insert(eventSourceKey, args.EventSource),
tag.Insert(eventTypeKey, args.EventType),
tag.Insert(eventScheme, args.EventScheme),
tag.Insert(sourceNameKey, args.Name),
tag.Insert(sourceResourceGroupKey, args.ResourceGroup),
metrics.MaybeInsertIntTag(responseCodeKey, responseCode, responseCode > 0),
Expand All @@ -135,12 +138,14 @@ func register() {
namespaceKey,
eventSourceKey,
eventTypeKey,
eventScheme,
sourceNameKey,
sourceResourceGroupKey,
responseCodeKey,
responseCodeClassKey,
responseError,
responseTimeout}
responseTimeout,
}

// Create view to see our measurements.
if err := view.Register(
Expand Down
4 changes: 4 additions & 0 deletions pkg/metrics/source/stats_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestStatsReporter(t *testing.T) {
EventSource: "unit-test",
Name: "testsource",
ResourceGroup: "testresourcegroup",
EventScheme: "http",
}

r, err := NewStatsReporter()
Expand All @@ -49,6 +50,7 @@ func TestStatsReporter(t *testing.T) {
metrics.LabelResourceGroup: "testresourcegroup",
metrics.LabelResponseCode: "202",
metrics.LabelResponseCodeClass: "2xx",
metrics.LabelEventScheme: "http",
}

retryWantTags := map[string]string{
Expand All @@ -59,6 +61,7 @@ func TestStatsReporter(t *testing.T) {
metrics.LabelResourceGroup: "testresourcegroup",
metrics.LabelResponseCode: "503",
metrics.LabelResponseCodeClass: "5xx",
metrics.LabelEventScheme: "http",
}

// test ReportEventCount and ReportRetryEventCount
Expand Down Expand Up @@ -86,6 +89,7 @@ func TestBadValues(t *testing.T) {

args := &ReportArgs{
Namespace: "😀",
EventScheme: "http",
}

if err := r.ReportEventCount(args, 200); err == nil {
Expand Down
22 changes: 22 additions & 0 deletions vendor/github.com/cloudevents/sdk-go/v2/event/event_reader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/cloudevents/sdk-go/v2/event/eventcontext.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.