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

Add mutations such as mutiplication/division to allow exposing metrics in the proper units #3129

Closed
frittentheke opened this issue Jan 6, 2021 · 6 comments · Fixed by #3515
Labels
keepalive An issue or PR that will be kept alive and never marked as stale.
Milestone

Comments

@frittentheke
Copy link
Contributor

frittentheke commented Jan 6, 2021

Is your feature request related to a problem? Please describe.
Some logs contain valuable metric data Promtail is able aggregate and expose as Prometheus metrics already.
Unfortunately the data is not always in the proper format / unit to follow the best-practices and to use the Prometheus recommended base-units (https://prometheus.io/docs/practices/naming/#base-units).
So a field extracted from a log could contain milliseconds instead of seconds or bits insteads of bytes.

Describe the solution you'd like
It would be great to have a few mutations such as multiplication or / division available which can be applied to fields.
Potentially this would could be covered by the template (https://grafana.com/docs/loki/latest/clients/promtail/stages/template/#supported-functions) feature and go-template. But unfortunately there are not arithmetic functions allowed / implemented (yet):

invalid template stage config: template: pipeline_template:1: function \"div\" not defined"

To not have to maintain a homegrown list of functions the Sprig library (http://masterminds.github.io/sprig/) could be added enabling more than enough magic to mutate things as required - i.e. use their divf on ms to become seconds.

Describe alternatives you've considered
This functionality cannot be covered by string manipulations such as the already available regex or the existing go template magic.

Additional context

@cyriltovena
Copy link
Contributor

There's another issue somewhere for this. I prefer to add slowly what we need instead of using sprig, this is mostly because it is run on server side.

@frittentheke
Copy link
Contributor Author

@cyriltovena thanks for your response !

I suppose you are talking about:

which are technically related, but they are more about LogQL than the metrics extraction.
In any case I suppose once implemented, those functions are likely applicable to all those cases.

@stale
Copy link

stale bot commented Feb 13, 2021

This issue has been automatically marked as stale because it has not had any activity in the past 30 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale A stale issue or PR that will automatically be closed. label Feb 13, 2021
@frittentheke
Copy link
Contributor Author

not stale

@stale stale bot removed the stale A stale issue or PR that will automatically be closed. label Feb 14, 2021
@cyriltovena cyriltovena added the keepalive An issue or PR that will be kept alive and never marked as stale. label Feb 15, 2021
@cyriltovena cyriltovena added this to the 2.3 milestone Feb 15, 2021
@frittentheke
Copy link
Contributor Author

@cyriltovena I believe this feature was implemented via merged PR #3434 ?

@cyriltovena
Copy link
Contributor

only for LogQL so far.

cyriltovena added a commit to cyriltovena/loki that referenced this issue Mar 19, 2021
Fixes grafana#3129

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
sandeepsukhani pushed a commit that referenced this issue Mar 26, 2021
* Add sprig text/template function to template stage.

Fixes #3129

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* nit.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* reset vendor file.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keepalive An issue or PR that will be kept alive and never marked as stale.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants