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

Idiomatic log metrics with customizable naming #597

Merged
merged 2 commits into from
Dec 27, 2022

Conversation

987Nabil
Copy link
Contributor

@987Nabil 987Nabil commented Dec 27, 2022

The current impl. creates many metrics, which is not idiomatic. They are all the same metric with different notions. Therefore I propose to use labels instead with only one counter.
Also I think being forced to use a certain metric name is not good, since orgs might enforce naming conventions.

I remember, that we have the option for custom naming in other zio metrics too. I think it was zio-http.

@987Nabil 987Nabil requested a review from a team as a code owner December 27, 2022 11:20
@987Nabil 987Nabil changed the title Idiomatic error log counter with customizable naming Idiomatic log counter with customizable naming Dec 27, 2022
@987Nabil 987Nabil force-pushed the custom-metric-names branch from 6e6b347 to eda55c2 Compare December 27, 2022 12:10
@987Nabil 987Nabil changed the title Idiomatic log counter with customizable naming Idiomatic log metrics with customizable naming Dec 27, 2022
@justcoon
Copy link
Contributor

hi @987Nabil,

thank you for contribution,

in my opinion is hard to say what is idiomatic in this case,

in various systems/frameworks/applications both solution are used:

  • custom metrics per problem/category
  • one common metric with tags

i think it it's about preferences in terms of options (of course sometimes one solution may be better then other ...)

originally i made metric per log level, to have similar style like in zio core (there are specific metrics, for zio_fiber_started, zio_fiber_successes, zio_fiber_failures),

basically in original PR (#590) i mentioned also alternative solution which is same like here in your PR

but yes, it is easier to change naming in case of common metric with tags

personally I am ok with your proposal, more like there may be question in relation to backward compatibility, because this change is not backward compatible

docs/metrics.md Outdated
* `LogLevel.All` -> `all`
* `LogLevel.Fatal` -> `fatal`
* `LogLevel.Error` -> `error`
* `LogLevel.Warning` -> `warning`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label for LogLevel.Warning is WARN
then this should be:

LogLevel.Warning -> warn

@987Nabil
Copy link
Contributor Author

@justcoon I think Scala api wise it is. Only the name of the metric is a problem. But this is out now for 2 days?

All places I came a long sofar prefer labels.
And it is afaik more efficient in the metric databases, since they are optimized for it.

docs/metrics.md Outdated
* `LogLevel.Info` -> `info`
* `LogLevel.Debug` -> `debug`
* `LogLevel.Trace` -> `trace`
* `LogLevel.None` -> `none`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label for LogLevel.Warning is OFF
then this should be:

LogLevel.None -> off

NOTE: here is bug also in original documentation

@justcoon
Copy link
Contributor

ok, that is true, that it is released just few days (and also there are holidays now)

i added some comments, also code needs to be reformatted (build failing on scalafmtCheck - there is sbt fix command)

@987Nabil
Copy link
Contributor Author

Always the formatter. I am used to formatting that is applied and pushed by the pipeline. But I think this only works for private repos.
I am updating.

@987Nabil 987Nabil force-pushed the custom-metric-names branch from eda55c2 to 922d030 Compare December 27, 2022 13:50
} yield ExitCode.success)
.provideLayer((ZLayer.succeed(MetricsConfig(200.millis)) ++ publisherLayer) >+> prometheusLayer)

}
```

Expected Console Output:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in relation to metric changes, console output for this example probably also changed,
i think you should run MetricsApp from examples and update it here

@jdegoes jdegoes merged commit 99a8c78 into zio:master Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants