xk6-loki
xk6-loki copied to clipboard
Suggestion: Override `instance` label value
When running the extension as a Deployment in Kubernetes, the hostname is always a new value. This can lead to unwanted/unexpected behaviour since the instance label value of streams contains the hostname.
I can think of two different options to implement custom labels, under with this suggestion falls:
Proposal 1
Instead of providing a map[string]int as optional fourth argument in the loki.Config constructor, extend it to map[string]interface{}, which can hold both an int value as well as a []string value.
If map value is of type int, then the current logic of generating the values stays the same.
If the map value is of type []string, then, instead of the generated values, the provided values are used for the label pool.
Since a key (label name) support both int and []string type, and the different labels have different generator functions (some or dynamic based on faker, some are static), this implementation is limited to the existing label names, because otherwise it would become overly completed to configure.
Example
const labels = {
"format": ["apache_common", "logfmt"],
"os": ["linux"],
"namespace": 3,
"app": 2,
"instance": ["localhost"],
};
const conf = new loki.Config(BASE_URL, 10000, 1.0, labels);
POC: https://github.com/grafana/xk6-loki/compare/chaudum/custom-labels?expand=1
Proposal 2
Introduce a new, optional fifth argument for the loki.Config constructor that is of type map[string][]string. With this argument, one can completely override the existing cardinality map with custom labels names and values.
The format label still needs to contain one or more values from the supported log formats.
Example
const labels = loki.Labels({
"format": ["logfmt"],
"os": ["linux"],
"namespace": ["loki-prod", "loki-dev"],
"container": ["distributor", "ingester", "querier", "query-frontend", "query-scheduler", "index-gateway", "compactor"],
"instance": ["localhost"],
});
const conf = new loki.Config(BASE_URL, 10000, 1.0, {}, labels);
POC: https://github.com/grafana/xk6-loki/compare/chaudum/custom-labels-2?expand=1
Personally I tend towards the 2nd proposal, since it is easier to understand. People often want to provide their own labels, and you could even read the values from a file in the setup context of the loadtest.
/cc @basvdl @vlad-diachenko
Hey @chaudum . what if we combine both solutions? we could change the type to :
map[string]struct{generatedValuesCount int, staticValues string[]}
so, users could specify either generatedValuesCount, a count of label values that will be generated using faker, or staticValues which is a label values pool.
map[string]struct{generatedValuesCount int, staticValues string[]}
The problem that I see here is that it would break backwards compatibility because the input type for the argument changes.
Allowing both map[string]int and map[string]struct{} and keep backwards compatibility would add a lot of complexity IMO.
yes, it might bring additional complexity but also it brings us flexibility and makes the config clear for the users. so we could do it. anyway, I also like Proposal 2.