From 5006ca715d12a571ecc463e0fc59a32c4e4d9cbb Mon Sep 17 00:00:00 2001 From: Krzysztof Kwapisiewicz Date: Fri, 8 Dec 2023 16:31:19 +0100 Subject: [PATCH 1/6] Add Global Cache OLAP telemetry --- pkg/otelcollector/consts/consts.go | 12 ++++++++---- .../internal/check_response_labels.go | 17 +++++++++++++---- .../metricsprocessor/internal/labels_filter.go | 6 ++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/pkg/otelcollector/consts/consts.go b/pkg/otelcollector/consts/consts.go index dba9e65ac1..22250791ab 100644 --- a/pkg/otelcollector/consts/consts.go +++ b/pkg/otelcollector/consts/consts.go @@ -87,10 +87,14 @@ const ( ApertureFlowStatusOK = "OK" // ApertureFlowStatusError const for error status. ApertureFlowStatusError = "Error" - // ApertureCacheLookupStatusLabel describes status of the cache lookup. - ApertureCacheLookupStatusLabel = "aperture.cache_lookup_status" - // ApertureCacheOperationStatusLabel describes status of the cache operation. - ApertureCacheOperationStatusLabel = "aperture.cache_operation_status" + // ApertureResultCacheLookupStatusLabel describes status of the cache lookup. + 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" /* HTTP Specific labels. */ diff --git a/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go b/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go index cba8becea2..d57648e717 100644 --- a/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go +++ b/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go @@ -59,10 +59,19 @@ func AddCheckResponseBasedLabels(attributes pcommon.Map, checkResponse *flowcont ) // Cache - if checkResponse.CacheLookupResponse != nil && checkResponse.CacheLookupResponse.ResultCacheResponse != nil { - resultCacheResponse := checkResponse.CacheLookupResponse.ResultCacheResponse - attributes.PutStr(otelconsts.ApertureCacheLookupStatusLabel, resultCacheResponse.LookupStatus.String()) - attributes.PutStr(otelconsts.ApertureCacheOperationStatusLabel, resultCacheResponse.OperationStatus.String()) + if checkResponse.CacheLookupResponse != nil { + if checkResponse.CacheLookupResponse.ResultCacheResponse != nil { + resultCacheResponse := checkResponse.CacheLookupResponse.ResultCacheResponse + attributes.PutStr(otelconsts.ApertureResultCacheLookupStatusLabel, resultCacheResponse.LookupStatus.String()) + attributes.PutStr(otelconsts.ApertureResultCacheOperationStatusLabel, resultCacheResponse.OperationStatus.String()) + } + for _, globalCacheResponse := range checkResponse.CacheLookupResponse.GlobalCacheResponses { + if globalCacheResponse == nil { + continue + } + attributes.PutStr(otelconsts.ApertureGlobalCacheLookupStatusLabel, globalCacheResponse.LookupStatus.String()) + attributes.PutStr(otelconsts.ApertureGlobalCacheOperationStatusLabel, globalCacheResponse.OperationStatus.String()) + } } // Note: Sorted alphabetically to help sorting attributes in rollupprocessor.key at least a bit. diff --git a/pkg/otelcollector/metricsprocessor/internal/labels_filter.go b/pkg/otelcollector/metricsprocessor/internal/labels_filter.go index 273a104197..c4b756dca7 100644 --- a/pkg/otelcollector/metricsprocessor/internal/labels_filter.go +++ b/pkg/otelcollector/metricsprocessor/internal/labels_filter.go @@ -40,8 +40,10 @@ var ( otelconsts.ResponseReceivedLabel, otelconsts.ApertureSourceServiceLabel, otelconsts.ApertureDestinationServiceLabel, - otelconsts.ApertureCacheLookupStatusLabel, - otelconsts.ApertureCacheOperationStatusLabel, + otelconsts.ApertureResultCacheLookupStatusLabel, + otelconsts.ApertureResultCacheOperationStatusLabel, + otelconsts.ApertureGlobalCacheLookupStatusLabel, + otelconsts.ApertureGlobalCacheOperationStatusLabel, } _includeAttributesHTTP = []string{ From 777950badbf96f1792d34923a7faa08177218a55 Mon Sep 17 00:00:00 2001 From: Krzysztof Kwapisiewicz Date: Mon, 11 Dec 2023 10:40:52 +0100 Subject: [PATCH 2/6] Add cache OLAP docs --- .../observability/flow-metrics/flow-metrics.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/content/reference/observability/flow-metrics/flow-metrics.md b/docs/content/reference/observability/flow-metrics/flow-metrics.md index e16db2db00..e5cc065662 100644 --- a/docs/content/reference/observability/flow-metrics/flow-metrics.md +++ b/docs/content/reference/observability/flow-metrics/flow-metrics.md @@ -25,13 +25,13 @@ and behavior. The stream can be stored and visualized in | --------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ------------------------- | | aperture.source | single | sdk, envoy | Aperture Flow source | SDKs, Envoy | | aperture.decision_type | single | DECISION_TYPE_ACCEPTED, DECISION_TYPE_REJECTED | Decision type taken by policy | SDKs, Envoy | -| aperture.reject_reason | single | REJECT_REASON_NONE, REJECT_REASON_RATE_LIMITED, REJECT_REASON_NO_TOKENS, REJECT_REASON_NOT_SAMPLED | Reject reason of the decision taken by policy | SDKs, Envoy | +| aperture.reject_reason | single | REJECT_REASON_NONE, REJECT_REASON_RATE_LIMITED, REJECT_REASON_NO_TOKENS, REJECT_REASON_NOT_SAMPLED | Reject reason of the decision taken by policy | SDKs, Envoy | | aperture.rate_limiters | multi-value | "policy_name:s1, component_id:18, policy_hash:5kZjj" | Rate limiters matched to the traffic | SDKs, Envoy | | aperture.dropping_rate_limiters | multi-value | "policy_name:s1, component_id:18, policy_hash:5kZjj" | Rate limiters dropping the traffic | SDKs, Envoy | | aperture.load_schedulers | multi-value | "policy_name:s1, component_id:13, policy_hash:5kZjj" | Concurrency limiters matched to the traffic | SDKs, Envoy | | aperture.dropping_load_schedulers | multi-value | "policy_name:s1, component_id:13, policy_hash:5kZjj" | Concurrency limiters dropping the traffic | SDKs, Envoy | -| aperture.samplers | multi-value | "policy_name:s1, component_id:18, policy_hash:5kZjj" | Samplers matched to the traffic | SDKs, Envoy | -| aperture.dropping_samplers | multi-value | "policy_name:s1, component_id:18, policy_hash:5kZjj" | Samplers dropping the traffic | SDKs, Envoy | +| aperture.samplers | multi-value | "policy_name:s1, component_id:18, policy_hash:5kZjj" | Samplers matched to the traffic | SDKs, Envoy | +| aperture.dropping_samplers | multi-value | "policy_name:s1, component_id:18, policy_hash:5kZjj" | Samplers dropping the traffic | SDKs, Envoy | | aperture.workloads | multi-value | "policy_name:s1, component_id:13, workload_index:0, policy_hash:5kZjj" | Workloads matched to the traffic | SDKs, Envoy | | aperture.dropping_workloads | multi-value | "policy_name:s1, component_id:13, workload_index:0, policy_hash:5kZjj" | Workloads dropping the traffic | SDKs, Envoy | | aperture.flux_meters | multi-value | s1 | Flux Meters matched to the traffic | SDKs, Envoy | @@ -41,7 +41,7 @@ and behavior. The stream can be stored and visualized in | aperture.services | multi-value | s1.demoapp.svc.cluster.local, s2.demoapp.svc.cluster.local | Services to which metrics refer | SDKs, Envoy | | aperture.control_point | single | type:TYPE_INGRESS, type:TYPE_EGRESS | Control point to which metrics refer | SDKs, Envoy | | aperture.flow.status | single | OK, Error | Denotes OK or Error across all protocols | SDKs, Envoy | -| response_received | single | true, false | Designates whether a response was received | SDKs, envoy | +| response_received | single | true, false | Designates whether a response was received | SDKs, Envoy | @@ -67,9 +67,13 @@ and behavior. The stream can be stored and visualized in -| Name | Type | Example Values | Description | Flow Control Integrations | -| --------------------- | ---- | -------------- | ------------------------------------------------ | ------------------------- | -| {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_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 | From a927175170693af96e8859c452c81c4e902d1262 Mon Sep 17 00:00:00 2001 From: Krzysztof Kwapisiewicz Date: Mon, 11 Dec 2023 11:28:56 +0100 Subject: [PATCH 3/6] Cache OLAP improvements --- .../metricsprocessor/internal/check_response_labels.go | 4 ++++ .../metricsprocessor/internal/labels_filter.go | 8 ++++---- pkg/otelcollector/metricsprocessor/processor.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go b/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go index d57648e717..074b2a46f2 100644 --- a/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go +++ b/pkg/otelcollector/metricsprocessor/internal/check_response_labels.go @@ -29,6 +29,10 @@ import ( // * otelconsts.ApertureClassifierErrorsLabel // * otelconsts.ApertureDecisionTypeLabel // * otelconsts.ApertureRejectReasonLabel +// * otelconsts.ApertureResultCacheLookupStatusLabel +// * otelconsts.ApertureResultCacheOperationStatusLabel +// * otelconsts.ApertureGlobalCacheLookupStatusLabel +// * otelconsts.ApertureGlobalCacheOperationStatusLabel // * dynamic flow labels. func AddCheckResponseBasedLabels(attributes pcommon.Map, checkResponse *flowcontrolv1.CheckResponse, sourceStr string) { // Aperture Processing Duration diff --git a/pkg/otelcollector/metricsprocessor/internal/labels_filter.go b/pkg/otelcollector/metricsprocessor/internal/labels_filter.go index c4b756dca7..673de9574b 100644 --- a/pkg/otelcollector/metricsprocessor/internal/labels_filter.go +++ b/pkg/otelcollector/metricsprocessor/internal/labels_filter.go @@ -40,10 +40,6 @@ var ( otelconsts.ResponseReceivedLabel, otelconsts.ApertureSourceServiceLabel, otelconsts.ApertureDestinationServiceLabel, - otelconsts.ApertureResultCacheLookupStatusLabel, - otelconsts.ApertureResultCacheOperationStatusLabel, - otelconsts.ApertureGlobalCacheLookupStatusLabel, - otelconsts.ApertureGlobalCacheOperationStatusLabel, } _includeAttributesHTTP = []string{ @@ -54,6 +50,10 @@ var ( _includeAttributesSDK = []string{ otelconsts.ApertureFlowStatusLabel, + otelconsts.ApertureResultCacheLookupStatusLabel, + otelconsts.ApertureResultCacheOperationStatusLabel, + otelconsts.ApertureGlobalCacheLookupStatusLabel, + otelconsts.ApertureGlobalCacheOperationStatusLabel, } includeListHTTP = utils.SliceToSet(append(_includeAttributesCommon, _includeAttributesHTTP...)) diff --git a/pkg/otelcollector/metricsprocessor/processor.go b/pkg/otelcollector/metricsprocessor/processor.go index aea7dfd689..5f863c7ff2 100644 --- a/pkg/otelcollector/metricsprocessor/processor.go +++ b/pkg/otelcollector/metricsprocessor/processor.go @@ -64,7 +64,7 @@ func (p *metricsProcessor) ConsumeLogs(ctx context.Context, ld plog.Logs) (plog. capacity := attributes.Len() + 5 + // EnvoySpecificLabels 1 + // FlowStatus - 17 + // CheckResponse + 21 + // CheckResponse len(checkResponse.GetTelemetryFlowLabels()) _ = capacity // Not calling EnsureCapacity as it's broken: From 211ec2de56eadfe2a8ee125e180c9200d5e8c946 Mon Sep 17 00:00:00 2001 From: Krzysztof Kwapisiewicz Date: Mon, 11 Dec 2023 13:20:22 +0100 Subject: [PATCH 4/6] 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...)) From 5e1d4c12245c1fdff6498e6d90021a94964d8cd6 Mon Sep 17 00:00:00 2001 From: Krzysztof Kwapisiewicz Date: Mon, 11 Dec 2023 14:16:23 +0100 Subject: [PATCH 5/6] Uncomment ensure capacity --- pkg/otelcollector/metricsprocessor/processor.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/otelcollector/metricsprocessor/processor.go b/pkg/otelcollector/metricsprocessor/processor.go index 5f863c7ff2..262f431fa8 100644 --- a/pkg/otelcollector/metricsprocessor/processor.go +++ b/pkg/otelcollector/metricsprocessor/processor.go @@ -66,10 +66,7 @@ func (p *metricsProcessor) ConsumeLogs(ctx context.Context, ld plog.Logs) (plog. 1 + // FlowStatus 21 + // CheckResponse len(checkResponse.GetTelemetryFlowLabels()) - _ = capacity - // Not calling EnsureCapacity as it's broken: - // https://github.com/open-telemetry/opentelemetry-collector/issues/7955 - // attributes.EnsureCapacity(capacity) + attributes.EnsureCapacity(capacity) } // Source specific processing From c1f8251111c6d6f28341a5bf613e5e0e99e636e2 Mon Sep 17 00:00:00 2001 From: Hardik Shingala Date: Mon, 11 Dec 2023 19:33:04 +0530 Subject: [PATCH 6/6] Fix bytes marshalling issue in js sdk --- sdks/aperture-js/sdk/flow.ts | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/sdks/aperture-js/sdk/flow.ts b/sdks/aperture-js/sdk/flow.ts index ba4b53234a..0bbe95897f 100644 --- a/sdks/aperture-js/sdk/flow.ts +++ b/sdks/aperture-js/sdk/flow.ts @@ -61,7 +61,7 @@ export interface Flow { span(): Span; end(): void; httpResponseCode(): Number | undefined; - retryAfter(): {seconds: string | undefined, nanos: number | undefined} + retryAfter(): { seconds: string | undefined, nanos: number | undefined } } /** @@ -95,7 +95,7 @@ export class _Flow implements Flow { if ( (!this.rampMode && this._checkResponse === null) || this._checkResponse?.decisionType === - _aperture_flowcontrol_check_v1_CheckResponse_DecisionType.DECISION_TYPE_ACCEPTED + _aperture_flowcontrol_check_v1_CheckResponse_DecisionType.DECISION_TYPE_ACCEPTED ) { return true; } else { @@ -360,9 +360,9 @@ export class _Flow implements Flow { */ retryAfter() { if (this._checkResponse) { - return {seconds: this._checkResponse?.waitTime?.seconds.toString(), nanos: this._checkResponse?.waitTime?.nanos }; + return { seconds: this._checkResponse?.waitTime?.seconds.toString(), nanos: this._checkResponse?.waitTime?.nanos }; } - return {seconds: undefined, nanos: undefined}; + return { seconds: undefined, nanos: undefined }; } /** @@ -403,6 +403,24 @@ export class _Flow implements Flow { // Current timestamp type: https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/timestamp.proto const localCheckResponse = this._checkResponse as any; + if (this._checkResponse.cacheLookupResponse?.resultCacheResponse?.value) { + localCheckResponse.cacheLookupResponse.resultCacheResponse.value = bufferToByteArrayJson( + this._checkResponse.cacheLookupResponse.resultCacheResponse.value, + ); + } + + if (this._checkResponse.cacheLookupResponse?.globalCacheResponses) { + Object.entries( + this._checkResponse.cacheLookupResponse.globalCacheResponses, + ).forEach(([key, value]) => { + if (value.value) { + localCheckResponse.cacheLookupResponse.globalCacheResponses[ + key + ].value = bufferToByteArrayJson(value.value); + } + }); + } + localCheckResponse.start = protoTimestampToJSON( this._checkResponse.start, ); @@ -437,6 +455,15 @@ export class _Flow implements Flow { } } +function bufferToByteArrayJson(buffer: Buffer) { + const byteArray = buffer.toJSON().data; + var hash = ""; + for (var i = 0; i < byteArray.length; i++) { + hash += String.fromCharCode(byteArray[i]); + } + return Buffer.from(hash).toString('base64'); +} + function protoTimestampToJSON( timestamp: _google_protobuf_Timestamp__Output | null, ) {