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

Suggestion: Override instance label value #35

Open
chaudum opened this issue May 3, 2022 · 4 comments
Open

Suggestion: Override instance label value #35

chaudum opened this issue May 3, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@chaudum
Copy link
Collaborator

chaudum commented May 3, 2022

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.

@chaudum chaudum added the enhancement New feature or request label May 3, 2022
@chaudum
Copy link
Collaborator Author

chaudum commented May 20, 2022

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

@vlad-diachenko
Copy link
Contributor

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.

@chaudum
Copy link
Collaborator Author

chaudum commented May 24, 2022

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.

@vlad-diachenko
Copy link
Contributor

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.

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

No branches or pull requests

2 participants