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 lang parameter to OpenWeathermap input plugin #6504

Merged
merged 6 commits into from
Oct 18, 2019
Merged

Add lang parameter to OpenWeathermap input plugin #6504

merged 6 commits into from
Oct 18, 2019

Conversation

reimda
Copy link
Contributor

@reimda reimda commented Oct 9, 2019

closes #6042

New fields: condition_description, condition_icon
New tags: condition_id, condition_main

Required for all PRs:

  • Associated README.md updated.
  • Has appropriate unit tests.

New fields: condition_description, condition_icon
New tags: condition_id, condition_main
@reimda reimda added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Oct 9, 2019
@reimda reimda added this to the 1.13.0 milestone Oct 9, 2019
@reimda reimda marked this pull request as ready for review October 9, 2019 23:13
plugins/inputs/openweathermap/README.md Outdated Show resolved Hide resolved
plugins/inputs/openweathermap/README.md Show resolved Hide resolved
@@ -42,6 +47,8 @@ https://openweathermap.org/city/2643743
- tags:
- city_id
- forecast
- condition_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Swap condition_id with condition_description, making it a tag, and this a field. Also, is the _description more valuable than the _main? It seems like they are essentially duplicate data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could be wrong but I think it makes more sense to have ID as a tag and description as a field. Description is the same information as ID, but human readable and localized. I would rather select ID=802 than description="scattered clouds: 25-50%" or possibly a localization like "Mäßig bewölkt". Using ID to select means you don't have to know which language was enabled in the telegraf conf when the data was collected.

Description/ID is more valuable than main. You could map ID to main's value and leave out main completely. I included it for the same reasons as icon- It's part of OWM's API and someone familiar with it would think it's missing if we don't include it.

I made main a tag because it's a single word and it isn't localized. It might make sense to make it a field instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's part of OWM's API and someone familiar with it would think it's missing if we don't include it

It's quite common for telegraf to not create a metric from everything provided by an api. Some things just don't make sense as time series data.

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding the human readable vs id: telegraf has standardized enum "codes" to be stored as fields and the string representations to be stored as tags. One example is the kube_inventory plugin (state and state_code):

"state_code": stateCode,
"terminated_reason": cs.State.Terminated.GetReason(),
}
tags := map[string]string{
"container_name": *c.Name,
"namespace": *p.Metadata.Namespace,
"node_name": *p.Spec.NodeName,
"pod_name": *p.Metadata.Name,
"state": state,

I would rather select ID=802

Very much agree. I'm not sure where/why you would do the other option. Both are still possible in either configuration from what I understand, but in influx, you can only group by tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The influxdb schema design docs have some advice on choosing tags vs fields (https://docs.influxdata.com/influxdb/v1.7/concepts/schema_and_data_layout/). It says to make it a tag if it's commonly queried or used in a group by. Only tags are indexed, so querying on fields is slow.

After reading those docs I think I'd like to leave id and main as tags and description as a field. I imagine querying on and grouping by conditions will be common, so main and id should be tags. If you want the general condition like snowy days, use main="snow". If you want a specific condition like all days with freezing rain, use id="511". I think description isn't going to be commonly queried because it's localized and too long, so it should be a field.

I think the difference between this and kube_inventory is that kube_inventory's state is short (one word), only has three values, and isn't localized. That makes state easier to use than state_code, so it fits the tags criteria better.

I'd be fine leaving out icon but I don't think it's hurting anything. It doesn't give you much over id and main for grouping or querying, so if it stays it should be a field. It's only really useful if you build custom ui and need a weather conditions icon. I'm leaning towards leaving it in and letting people filter it out if they don't want it.

plugins/inputs/openweathermap/openweathermap.go Outdated Show resolved Hide resolved
plugins/inputs/openweathermap/openweathermap.go Outdated Show resolved Hide resolved
Copy link
Contributor

@danielnelson danielnelson left a comment

Choose a reason for hiding this comment

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

I think the tag/field split is about right, I could imagine all the items being tags too since they all have a finite set of values, but I wouldn't go further in the field direction.

plugins/inputs/openweathermap/openweathermap.go Outdated Show resolved Hide resolved
plugins/inputs/openweathermap/openweathermap.go Outdated Show resolved Hide resolved
plugins/inputs/openweathermap/openweathermap.go Outdated Show resolved Hide resolved
plugins/inputs/openweathermap/openweathermap_test.go Outdated Show resolved Hide resolved
plugins/inputs/openweathermap/openweathermap_test.go Outdated Show resolved Hide resolved
plugins/inputs/openweathermap/openweathermap_test.go Outdated Show resolved Hide resolved
@reimda
Copy link
Contributor Author

reimda commented Oct 15, 2019

I take it OWM's default unit is "metric" if none is specified? My only hesitation doing it this way is that it gives them the control, if they change their default settings, telegraf user's are affected..

No change needed unless "metric" isn't their default unit

I checked on OWM's default unit and actually it isn't metric. To avoid changing behavior for telegraf people upgrading, I added back the telegraf metric default. There's still a check for expected units so you won't accidentally get metric if you misspelled standard or imperial like you did before.

@reimda reimda requested a review from glinton October 16, 2019 20:01
plugins/inputs/openweathermap/openweathermap.go Outdated Show resolved Hide resolved
plugins/inputs/openweathermap/openweathermap.go Outdated Show resolved Hide resolved
@reimda reimda merged commit 0096278 into master Oct 18, 2019
@reimda reimda deleted the feat/6042 branch October 18, 2019 19:48
athoune pushed a commit to bearstech/telegraf that referenced this pull request Apr 17, 2020
idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lang parameter for openweathermap
3 participants