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

Add Global Cache OLAP telemetry #3041

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
| --------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ------------------------- |
| aperture.source | single | sdk, envoy | Aperture Flow source | SDKs, Envoy |
kwapik marked this conversation as resolved.
Show resolved Hide resolved
| 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 |
kwapik marked this conversation as resolved.
Show resolved Hide resolved
| 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 |
kwapik marked this conversation as resolved.
Show resolved Hide resolved
| 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 |
| aperture.flow_label_keys | multi-value | http.host, http.method, http.request.header.content_length | Flow labels matched to the traffic | SDKs, Envoy |

Check warning on line 38 in docs/content/reference/observability/flow-metrics/flow-metrics.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Host`, ` host` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING Raw Output: docs/content/reference/observability/flow-metrics/flow-metrics.md:38:57: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Host`, ` host` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING

Check warning on line 38 in docs/content/reference/observability/flow-metrics/flow-metrics.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Method`, ` method` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING Raw Output: docs/content/reference/observability/flow-metrics/flow-metrics.md:38:68: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Method`, ` method` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
| aperture.classifiers | multi-value | "policy_name:s1, classifier_index:0" | Classifiers matched to the traffic | SDKs, Envoy |

Check warning on line 39 in docs/content/reference/observability/flow-metrics/flow-metrics.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Classifiers`, ` classifiers` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING Raw Output: docs/content/reference/observability/flow-metrics/flow-metrics.md:39:11: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Classifiers`, ` classifiers` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
| aperture.classifier_errors | multi-value | "[ERROR_NONE, ERROR_EVAL_FAILED, ERROR_EMPTY_RESULTSET, ERROR_AMBIGUOUS_RESULTSET, ERROR_MULTI_EXPRESSION, ERROR_EXPRESSION_NOT_MAP], policy_name:s1, classifier_index:0" | Encountered classifier errors for specified policy | SDKs, Envoy |
| 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 |

<!-- vale on -->

Expand All @@ -54,11 +54,11 @@
| http.status_code | single | 200, 429, 503 | HTTP status code of the response | Envoy |
| http.request_content_length | single | 0, 53 | Length of the HTTP request content in bytes | Envoy |
| http.response_content_length | single | 201, 77 | Length of the HTTP response content in bytes | Envoy |
| http.method | single | GET, POST | HTTP method of the response | Envoy |

Check warning on line 57 in docs/content/reference/observability/flow-metrics/flow-metrics.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Method`, ` method` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING Raw Output: docs/content/reference/observability/flow-metrics/flow-metrics.md:57:7: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Method`, ` method` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
| http.target | single | /request | Target endpoint of the response | Envoy |

Check warning on line 58 in docs/content/reference/observability/flow-metrics/flow-metrics.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Target`, ` target` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING Raw Output: docs/content/reference/observability/flow-metrics/flow-metrics.md:58:7: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Target`, ` target` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
| http.host | single | s1.demoapp.svc.cluster.local, s2.demoapp.svc.cluster.local | Host address of the response | Envoy |

Check warning on line 59 in docs/content/reference/observability/flow-metrics/flow-metrics.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Host`, ` host` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING Raw Output: docs/content/reference/observability/flow-metrics/flow-metrics.md:59:7: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Host`, ` host` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
| http.scheme | single | http | HTTP scheme of the response | Envoy |

Check warning on line 60 in docs/content/reference/observability/flow-metrics/flow-metrics.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Scheme`, ` scheme` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING Raw Output: docs/content/reference/observability/flow-metrics/flow-metrics.md:60:7: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Scheme`, ` scheme` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
| http.flavor | single | 1.1 | HTTP protocol version | Envoy |

Check warning on line 61 in docs/content/reference/observability/flow-metrics/flow-metrics.md

View workflow job for this annotation

GitHub Actions / languagetool

[LanguageTool] reported by reviewdog 🐶 If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Flavor`, ` flavor` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING Raw Output: docs/content/reference/observability/flow-metrics/flow-metrics.md:61:7: If a new sentence starts here, add a space and start with an uppercase letter. (LC_AFTER_PERIOD[1]) Suggestions: ` Flavor`, ` flavor` Rule: https://community.languagetool.org/rule/show/LC_AFTER_PERIOD?lang=en-US&subId=1 Category: CASING
| {user-defined-labels} | | | Configured through [_Classifier_][classifier] | Envoy |

<!-- vale on -->
Expand All @@ -67,9 +67,13 @@

<!-- vale off -->

| 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_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 |

<!-- vale on -->

Expand Down
12 changes: 8 additions & 4 deletions pkg/otelcollector/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
// 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. */

Expand Down
harjotgill marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
// * otelconsts.ApertureClassifierErrorsLabel
// * otelconsts.ApertureDecisionTypeLabel
// * otelconsts.ApertureRejectReasonLabel
// * otelconsts.ApertureResultCacheLookupStatusLabel
// * otelconsts.ApertureResultCacheOperationStatusLabel
// * otelconsts.ApertureGlobalCacheLookupStatusesLabel
// * otelconsts.ApertureGlobalCacheOperationStatusesLabel
// * dynamic flow labels.
func AddCheckResponseBasedLabels(attributes pcommon.Map, checkResponse *flowcontrolv1.CheckResponse, sourceStr string) {
// Aperture Processing Duration
Expand Down Expand Up @@ -59,10 +63,21 @@ 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())
}
globalCacheLookupStatuses := attributes.PutEmptySlice(otelconsts.ApertureGlobalCacheLookupStatusesLabel)
globalCacheOperationStatuses := attributes.PutEmptySlice(otelconsts.ApertureGlobalCacheOperationStatusesLabel)
for _, globalCacheResponse := range checkResponse.CacheLookupResponse.GlobalCacheResponses {
if globalCacheResponse == nil {
continue
}
globalCacheLookupStatuses.AppendEmpty().SetStr(globalCacheResponse.LookupStatus.String())
globalCacheOperationStatuses.AppendEmpty().SetStr(globalCacheResponse.OperationStatus.String())
kwapik marked this conversation as resolved.
Show resolved Hide resolved
}
}

// Note: Sorted alphabetically to help sorting attributes in rollupprocessor.key at least a bit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ var (
otelconsts.ResponseReceivedLabel,
otelconsts.ApertureSourceServiceLabel,
otelconsts.ApertureDestinationServiceLabel,
otelconsts.ApertureCacheLookupStatusLabel,
otelconsts.ApertureCacheOperationStatusLabel,
}

_includeAttributesHTTP = []string{
Expand All @@ -52,6 +50,10 @@ var (

_includeAttributesSDK = []string{
otelconsts.ApertureFlowStatusLabel,
otelconsts.ApertureResultCacheLookupStatusLabel,
otelconsts.ApertureResultCacheOperationStatusLabel,
otelconsts.ApertureGlobalCacheLookupStatusesLabel,
otelconsts.ApertureGlobalCacheOperationStatusesLabel,
}

includeListHTTP = utils.SliceToSet(append(_includeAttributesCommon, _includeAttributesHTTP...))
Expand Down
7 changes: 2 additions & 5 deletions pkg/otelcollector/metricsprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ 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:
// https://github.com/open-telemetry/opentelemetry-collector/issues/7955
// attributes.EnsureCapacity(capacity)
attributes.EnsureCapacity(capacity)
}

// Source specific processing
Expand Down
35 changes: 31 additions & 4 deletions sdks/aperture-js/sdk/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

/**
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 };
}

/**
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
) {
Expand Down
Loading