Skip to content

Commit

Permalink
Jsonnet: validate Kafka client ID (#9573)
Browse files Browse the repository at this point in the history
* Jsonnet: validate Kafka client ID

Signed-off-by: Marco Pracucci <[email protected]>

* Add CHANGELOG entry

Signed-off-by: Marco Pracucci <[email protected]>

* Allow comma too

Signed-off-by: Marco Pracucci <[email protected]>

---------

Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci authored Oct 9, 2024
1 parent 9907ea8 commit 473f25e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* [ENHANCEMENT] Add `ingest_storage_ingester_autoscaling_scale_up_stabilization_window_seconds` and `ingest_storage_ingester_autoscaling_scale_down_stabilization_window_seconds` config options to make stabilization window for ingester autoscaling when using ingest-storage configurable. #9445
* [ENHANCEMENT] Make label-selector in ReplicaTemplate/ingester-zone-a object configurable when using ingest-storage. #9480
* [ENHANCEMENT] Add `querier_only_args` option to specify CLI flags that apply only to queriers but not ruler-queriers. #9503
* [ENHANCEMENT] Validate the Kafka client ID configured when ingest storage is enabled. #9573

### Mimirtool

Expand Down
22 changes: 20 additions & 2 deletions operations/mimir/ingest-storage.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,30 @@

if std.length(cleanSettings) > 0 then
// Build the Kafka client ID from settings. Sort the key-value pairs to get a stable output.
std.join(',', std.sort(
local clientID = std.join(',', std.sort(
[
key + '=' + cleanSettings[key]
for key in std.objectFields(cleanSettings)
]
))
));

// The client ID can be up to 255 characters in length (limit hardcoded in franz-go), and can include
// the following characters:
// a-z, A-Z, 0-9, . (dot), _ (underscore), - (dash), = (equal), "," (comma).
local isValid(input) =
std.length(
// Build an array of invalid characters.
[
char
for char in std.stringChars(clientID)
if !std.member('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-=,', char)
]
) == 0;

assert std.length(clientID) < 256 : 'the Kafka client ID must be less than 256 characters (actual: %s)' % clientID;
assert isValid(clientID) : 'the Kafka client ID contains invalid characters (actual: %s)' % clientID;

clientID
else
// Explicitly use null so that the CLI flag will not be set at all (instead of getting set to an empty string).
null,
Expand Down

0 comments on commit 473f25e

Please sign in to comment.