From 211ec2de56eadfe2a8ee125e180c9200d5e8c946 Mon Sep 17 00:00:00 2001 From: Krzysztof Kwapisiewicz Date: Mon, 11 Dec 2023 13:20:22 +0100 Subject: [PATCH] Make global cache OLAP multi-value --- .../flow-metrics/flow-metrics.md | 14 ++++---- pkg/otelcollector/consts/consts.go | 8 ++--- .../internal/check_response_labels.go | 10 +++--- .../internal/check_response_labels_test.go | 36 +++++++++++++++++++ .../internal/labels_filter.go | 4 +-- 5 files changed, 55 insertions(+), 17 deletions(-) diff --git a/docs/content/reference/observability/flow-metrics/flow-metrics.md b/docs/content/reference/observability/flow-metrics/flow-metrics.md index e5cc065662..5e43b43a02 100644 --- a/docs/content/reference/observability/flow-metrics/flow-metrics.md +++ b/docs/content/reference/observability/flow-metrics/flow-metrics.md @@ -67,13 +67,13 @@ and behavior. The stream can be stored and visualized in -| Name | Type | Example Values | Description | Flow Control Integrations | -| -------------------------------------- | ------ | -------------- | ------------------------------------------------ | ------------------------- | -| aperture.cache_lookup_status | single | HIT, MISS | Result of result cache lookup | SDKs | -| aperture.cache_operation_status | single | SUCCESS, ERROR | Result of result cache operation | SDKs | -| aperture.global_cache_lookup_status | single | HIT, MISS | Result of global cache lookup | SDKs | -| aperture.global_cache_operation_status | single | SUCCESS, ERROR | Result of global cache operation | SDKs | -| {user-defined-labels} | | | Explicitly passed through FlowStart call in SDKs | SDKs | +| Name | Type | Example Values | Description | Flow Control Integrations | +| ---------------------------------------- | ----------- | -------------- | ------------------------------------------------ | ------------------------- | +| aperture.cache_lookup_status | single | HIT, MISS | Result of result cache lookup | SDKs | +| aperture.cache_operation_status | single | SUCCESS, ERROR | Result of result cache operation | SDKs | +| aperture.global_cache_lookup_statuses | multi-value | HIT, MISS | Results of global cache lookups | SDKs | +| aperture.global_cache_operation_statuses | multi-value | SUCCESS, ERROR | Results of global cache operations | SDKs | +| {user-defined-labels} | | | Explicitly passed through FlowStart call in SDKs | SDKs | diff --git a/pkg/otelcollector/consts/consts.go b/pkg/otelcollector/consts/consts.go index 22250791ab..f40838a64d 100644 --- a/pkg/otelcollector/consts/consts.go +++ b/pkg/otelcollector/consts/consts.go @@ -91,10 +91,10 @@ const ( ApertureResultCacheLookupStatusLabel = "aperture.cache_lookup_status" // ApertureResultCacheOperationStatusLabel describes status of the cache operation. ApertureResultCacheOperationStatusLabel = "aperture.cache_operation_status" - // ApertureGlobalCacheLookupStatusLabel describes status of the cache lookup. - ApertureGlobalCacheLookupStatusLabel = "aperture.global_cache_lookup_status" - // ApertureGlobalCacheOperationStatusLabel describes status of the cache operation. - ApertureGlobalCacheOperationStatusLabel = "aperture.global_cache_operation_status" + // ApertureGlobalCacheLookupStatusesLabel describes statuses of the global cache lookups. + ApertureGlobalCacheLookupStatusesLabel = "aperture.global_cache_lookup_statuses" + // ApertureGlobalCacheOperationStatusesLabel describes statuses of the global cache operations. + ApertureGlobalCacheOperationStatusesLabel = "aperture.global_cache_operation_statuses" /* HTTP Specific labels. */ diff --git a/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go b/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go index 074b2a46f2..841ad72419 100644 --- a/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go +++ b/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go @@ -31,8 +31,8 @@ import ( // * otelconsts.ApertureRejectReasonLabel // * otelconsts.ApertureResultCacheLookupStatusLabel // * otelconsts.ApertureResultCacheOperationStatusLabel -// * otelconsts.ApertureGlobalCacheLookupStatusLabel -// * otelconsts.ApertureGlobalCacheOperationStatusLabel +// * otelconsts.ApertureGlobalCacheLookupStatusesLabel +// * otelconsts.ApertureGlobalCacheOperationStatusesLabel // * dynamic flow labels. func AddCheckResponseBasedLabels(attributes pcommon.Map, checkResponse *flowcontrolv1.CheckResponse, sourceStr string) { // Aperture Processing Duration @@ -69,12 +69,14 @@ func AddCheckResponseBasedLabels(attributes pcommon.Map, checkResponse *flowcont attributes.PutStr(otelconsts.ApertureResultCacheLookupStatusLabel, resultCacheResponse.LookupStatus.String()) attributes.PutStr(otelconsts.ApertureResultCacheOperationStatusLabel, resultCacheResponse.OperationStatus.String()) } + globalCacheLookupStatuses := attributes.PutEmptySlice(otelconsts.ApertureGlobalCacheLookupStatusesLabel) + globalCacheOperationStatuses := attributes.PutEmptySlice(otelconsts.ApertureGlobalCacheOperationStatusesLabel) for _, globalCacheResponse := range checkResponse.CacheLookupResponse.GlobalCacheResponses { if globalCacheResponse == nil { continue } - attributes.PutStr(otelconsts.ApertureGlobalCacheLookupStatusLabel, globalCacheResponse.LookupStatus.String()) - attributes.PutStr(otelconsts.ApertureGlobalCacheOperationStatusLabel, globalCacheResponse.OperationStatus.String()) + globalCacheLookupStatuses.AppendEmpty().SetStr(globalCacheResponse.LookupStatus.String()) + globalCacheOperationStatuses.AppendEmpty().SetStr(globalCacheResponse.OperationStatus.String()) } } diff --git a/pkg/otelcollector/metricsprocessor/internal/check_response_labels_test.go b/pkg/otelcollector/metricsprocessor/internal/check_response_labels_test.go index b8d625a773..07210cf50b 100644 --- a/pkg/otelcollector/metricsprocessor/internal/check_response_labels_test.go +++ b/pkg/otelcollector/metricsprocessor/internal/check_response_labels_test.go @@ -138,6 +138,42 @@ var _ = DescribeTable("Check Response labels", func(checkResponse *flowcontrolv1 otelconsts.ApertureClassifierErrorsLabel: []interface{}{"ERROR_MULTI_EXPRESSION,policy_name:foo,classifier_index:42,policy_hash:bar"}, }, ), + + Entry("Sets result cache dimensions", + &flowcontrolv1.CheckResponse{ + CacheLookupResponse: &flowcontrolv1.CacheLookupResponse{ + ResultCacheResponse: &flowcontrolv1.KeyLookupResponse{ + LookupStatus: flowcontrolv1.CacheLookupStatus_MISS, + OperationStatus: flowcontrolv1.CacheOperationStatus_ERROR, + }, + }, + }, + map[string]interface{}{ + otelconsts.ApertureResultCacheLookupStatusLabel: "MISS", + otelconsts.ApertureResultCacheOperationStatusLabel: "ERROR", + }, + ), + + Entry("Sets global cache dimensions", + &flowcontrolv1.CheckResponse{ + CacheLookupResponse: &flowcontrolv1.CacheLookupResponse{ + GlobalCacheResponses: map[string]*flowcontrolv1.KeyLookupResponse{ + "foo": { + LookupStatus: flowcontrolv1.CacheLookupStatus_HIT, + OperationStatus: flowcontrolv1.CacheOperationStatus_SUCCESS, + }, + "bar": { + LookupStatus: flowcontrolv1.CacheLookupStatus_MISS, + OperationStatus: flowcontrolv1.CacheOperationStatus_ERROR, + }, + }, + }, + }, + map[string]interface{}{ + otelconsts.ApertureGlobalCacheLookupStatusesLabel: []interface{}{"HIT", "MISS"}, + otelconsts.ApertureGlobalCacheOperationStatusesLabel: []interface{}{"SUCCESS", "ERROR"}, + }, + ), ) var _ = Describe("AddFlowLabels", func() { diff --git a/pkg/otelcollector/metricsprocessor/internal/labels_filter.go b/pkg/otelcollector/metricsprocessor/internal/labels_filter.go index 673de9574b..f654872991 100644 --- a/pkg/otelcollector/metricsprocessor/internal/labels_filter.go +++ b/pkg/otelcollector/metricsprocessor/internal/labels_filter.go @@ -52,8 +52,8 @@ var ( otelconsts.ApertureFlowStatusLabel, otelconsts.ApertureResultCacheLookupStatusLabel, otelconsts.ApertureResultCacheOperationStatusLabel, - otelconsts.ApertureGlobalCacheLookupStatusLabel, - otelconsts.ApertureGlobalCacheOperationStatusLabel, + otelconsts.ApertureGlobalCacheLookupStatusesLabel, + otelconsts.ApertureGlobalCacheOperationStatusesLabel, } includeListHTTP = utils.SliceToSet(append(_includeAttributesCommon, _includeAttributesHTTP...))