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

[AlibabaCloudLogService] sanitize labels for metrics #3454

Merged
merged 4 commits into from
Jun 1, 2021

Conversation

shabicheng
Copy link
Contributor

Description:

OpenTelemetry metric's labels contains '.' or others none Letter or Digit characters, the alibabacloudlogserviceexporter do not replace these characters, so promQL will cause errors like "promql error: 1:33: parse error: unexpected character inside braces: '.'"

So we sanitize labels before send to sls, the code is almost copied from : https://github.com/open-telemetry/opentelemetry-collector/blob/main/exporter/prometheusexporter/sanitize.go

Link to tracking Issue:

#3429

Testing:

Documentation:

@shabicheng shabicheng requested a review from a team May 24, 2021 02:05
Copy link
Contributor

@qiansheng91 qiansheng91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prometheus exporter sanitizes the metric name and label key and that the AlibabaCloudLogService export only sanitizes the label key, Does the exporter need to concern it too?

@shabicheng
Copy link
Contributor Author

The prometheus exporter sanitizes the metric name and label key and that the AlibabaCloudLogService export only sanitizes the label key, Does the exporter need to concern it too?

Metric names have already sanitized in formatMetricName : https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/alibabacloudlogserviceexporter/metricsdata_to_logservice.go#L139

Copy link
Contributor

@qiansheng91 qiansheng91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

func (kv *KeyValues) Sort() { sort.Sort(kv) }

func (kv *KeyValues) Sort() {
// sanitize label keys before sort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't sanitization happen on insertion, not sorting? It seems mysterious for a sort method to modify the data itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, sanitize keys when insert

@@ -64,6 +68,7 @@ func (kv *KeyValues) Replace(key, value string) {

func (kv *KeyValues) AppendMap(mapVal map[string]string) {
for key, value := range mapVal {
key = sanitize(key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you can replace these 5 lines with calling the Append function

Copy link
Contributor Author

@shabicheng shabicheng May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, AppendMap can call Append directly

@@ -51,9 +51,13 @@ func (kv *KeyValues) Swap(i, j int) {
kv.keyValues[i], kv.keyValues[j] = kv.keyValues[j], kv.keyValues[i]
}
func (kv *KeyValues) Less(i, j int) bool { return kv.keyValues[i].Key < kv.keyValues[j].Key }
func (kv *KeyValues) Sort() { sort.Sort(kv) }

func (kv *KeyValues) Sort() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add unit tests for this file to demonstrate the sanitization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants