Skip to content

Commit

Permalink
model: sanitize/de-dot keys for labels, custom, and marks (#4465) (#4527
Browse files Browse the repository at this point in the history
)

* model: sanitize label keys

Replace reserved label key characters with '_', alleviating clients
from having to do this.

Also, optimise how we merge global and event-specific labels. Instead
of adding all global labels and then using utility.DeepUpdate, de-dot
the label keys first and range over the two maps to create a second map.
Because the labels keys cannot have dots, we do not need to deep merge.

* model: sanitize "custom" attribute keys

Sanitize the keys of "custom" context using the same
logic applied to labels. Also, drop the model.Custom
type and just use common.MapStr. This eliminates some
unnecessary pointer indirection.

* model: sanitize "marks" keys

* model/modeldecoder: drop label key regexp rules

* Add changelog entry
  • Loading branch information
axw authored Dec 14, 2020
1 parent 83e5ab4 commit c9b29e0
Show file tree
Hide file tree
Showing 39 changed files with 337 additions and 445 deletions.
5 changes: 2 additions & 3 deletions beater/beater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ func setupBeater(
// Add a label to test that everything
// goes through the wrapped reporter.
if tf.Labels == nil {
labels := make(model.Labels)
tf.Labels = &labels
tf.Labels = common.MapStr{}
}
(*tf.Labels)["wrapped_reporter"] = true
tf.Labels["wrapped_reporter"] = true
}
}
return origReporter(ctx, req)
Expand Down
25 changes: 9 additions & 16 deletions docs/spec/rumv3/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,22 @@
"type": [
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {}
}
]
},
"g": {
"description": "Tags are a flat mapping of user-defined tags. Allowed value types are string, boolean and number values. Tags are indexed and searchable.",
"type": [
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"p": {
Expand Down
19 changes: 8 additions & 11 deletions docs/spec/rumv3/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"se": {
Expand Down
19 changes: 8 additions & 11 deletions docs/spec/rumv3/metricset.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"sa": {
Expand Down
19 changes: 8 additions & 11 deletions docs/spec/rumv3/span.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"h": {
Expand Down
85 changes: 33 additions & 52 deletions docs/spec/rumv3/transaction.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,22 @@
"type": [
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {}
}
]
},
"g": {
"description": "Tags are a flat mapping of user-defined tags. Allowed value types are string, boolean and number values. Tags are indexed and searchable.",
"type": [
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"p": {
Expand Down Expand Up @@ -419,22 +412,16 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"additionalProperties": {
"type": [
"null",
"object"
],
"additionalProperties": {
"type": [
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"number"
]
}
}
"number"
]
}
}
},
Expand All @@ -451,17 +438,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"sa": {
Expand Down Expand Up @@ -723,17 +707,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"h": {
Expand Down
25 changes: 9 additions & 16 deletions docs/spec/v2/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
"type": [
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {}
}
]
},
"experimental": {
"description": "Experimental information is only processed when APM Server is started in development mode and should only be used by APM agent developers implementing new, unreleased features. The format is unspecified."
Expand Down Expand Up @@ -516,17 +512,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"user": {
Expand Down
19 changes: 8 additions & 11 deletions docs/spec/v2/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"process": {
Expand Down
19 changes: 8 additions & 11 deletions docs/spec/v2/metricset.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
},
"timestamp": {
Expand Down
19 changes: 8 additions & 11 deletions docs/spec/v2/span.json
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,14 @@
"null",
"object"
],
"additionalProperties": false,
"patternProperties": {
"^[^.*\"]*$": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
"additionalProperties": {
"type": [
"null",
"string",
"boolean",
"number"
],
"maxLength": 1024
}
}
}
Expand Down
Loading

0 comments on commit c9b29e0

Please sign in to comment.