open-telemetry / opentelemetry-collector-contrib

Contrib repository for the OpenTelemetry Collector
https://opentelemetry.io
Apache License 2.0
2.72k stars 2.16k forks source link

Expand time units for `ttl` config option #33686

Open SpencerTorres opened 1 week ago

SpencerTorres commented 1 week ago

Component(s)

exporter/clickhouse

Describe the issue you're reporting

When I saw we had two config options, ttl_days and ttl, it made sense to pick one (as we did recently by removing ttl_days in #33648)

Unfortunately when I approved this, I didn't realize that the largest unit of time for time.Duration is hours (h)

For telemetry use cases (mainly logging), data is kept for much longer than most people measure in hours. For example, I know a day is 24h, but what if I want to keep my log data for 6 months? While configuring my exporter I thought I could simply do 180d, but this of course fails to parse. It's not that doing the calculation to write 4320h is hard, it's just incredibly unintuitive. It's an easy mistake to make to type d there, especially for those who don't know Go and the time package.

The majority of units in time.ParseDuration are too small to be usable for a Database TTL config.

I believe it would be convenient to expand this to at least include days (d), but if we were to do this, where would be the best place?

Here are the different options, in order of least complexity:

  1. re-add ttl_days. We can still mark it as deprecated, but it is very convenient.
  2. In clickhouseexporter: we can change ttl from time.Duration to string and parse it in the local config parser function. We would add some logic for when the time contains d, but otherwise fallback to to time.ParseDuration.
  3. In OTel confmap: We can modify the hook here, so that all other components and configs can benefit from the change. We would have to write our own hook with the same change as option 1.
  4. In go-viper: This is the top-most parser we could modify without modifying Go itself. time.Duration does not have Unmarshal* functions declared, so this module adds a hook to include it. We could add a new function called StringToTimeDurationExtendedHookFunc to expand the current behavior, and then use it in OTel confmap.

This would be a non-breaking change since it doesn't affect any of the existing units. This change could benefit all OTel configs, not just ClickHouse exporter. Let me know what you think.

Thanks!

Note in case anyone points it out: This convenience is for users on Earth, and the conventional understanding that a day is 24 hours, rounded for convenience.