influxdata / influxdata/influxdb
Add Last-Modified header to telegraf api
- Dominant language
- Rust
- Stars
- 31.7k
- Forks
- 3.7k
- Avg merge
- 13h 37m
- Merged PRs (30d)
- 8
Description
__Use case:__
This PR merged on June 3rd on telegraf : [telegraf/PR 15388](https://github.com/influxdata/telegraf/pull/15388) added a watcher for telegraf remote config.
It was released on telegraf version 1.31.0 on June 10th: [Changelog 1.31.0](https://github.com/influxdata/telegraf/blob/master/CHANGELOG.md#v1310-2024-06-10).
The watcher polls on a configurable time (`--config-url-watch-interval` option on telegraf) the remote config hosted on the Influx server (eg: https://influxdb.example.domain:8086/api/v2/telegrafs/xxxxxxxxxxxxxxx) and looks at the `Last-Modified` header on the response ([cmd/telegraf/telegraf.go#L265](https://github.com/influxdata/telegraf/blob/master/cmd/telegraf/telegraf.go#L265)) to determine if the configuration has changed.
__Proposal:__
In accordance to this new capability of telegraf, Influxdb should add the `Last-Modifed` header on the **GET** response of the endpoint `/api/v2/telegrafs/{CONFIG_ID}`
__Current behaviour:__
This telegraf watcher does not work as Influxdb does not provide the Last-Modifed header:
``` powershell
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add("Authorization", "Bearer $Token")
$response=Invoke-WebRequest -Uri "https://influxdb.example.domain:8086/api/v2/telegrafs/xxxxxxxxxxxxxxx" -Headers $Headers
$response.Headers
Key Value
--- -----
Transfer-Encoding chunked
Connection keep-alive
X-Influxdb-Build OSS
X-Influxdb-Version v2.7.7
Content-Type application/json; charset=utf-8
Date Tue, 23 Jul 2024 17:48:28 GMT
```
So, telegraf cannot reload the configuration. Here is the log output when I put telegraf in debug mode:
``` log
2024-07-23T17:01:58Z E! Last-Modified header not found, stopping the watcher for https://influxdb.example.domain:8086/api/v2/telegrafs/xxxxxxxxxxxxxxx
```
__Desired behaviour:__
``` powershell
$Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$Headers.Add("Authorization", "Bearer $Token")
$response=Invoke-WebRequest -Uri "https://influxdb.example.domain:8086/api/v2/telegrafs/xxxxxxxxxxxxxxx" -Headers $Headers
$response.Headers
Key Value
--- -----
Transfer-Encoding chunked
Connection keep-alive
Last-Modified Tue, 23 Jul 2024 16:48:28 GMT # I don't know what is the date format accepted by telegraf
X-Influxdb-Build OSS
X-Influxdb-Version v2.7.7
Content-Type application/json; charset=utf-8
Date Tue, 23 Jul 2024 17:48:28 GMT
```
__Notes:__
I search on the Issues, on the pending Pull Requests and on the web, and I didn't find reference on this for Influxdb.
Also, I create a feature request and not a bug because from my point of view, it is not a bug from Influx, but rather a new capability from telegraf not yet implemented on Influxdb.
I hope that I didn't forget anything here.
Thanks for the help.
Contributor guide
Research direction
Start at the GET endpoint /api/v2/telegrafs/{CONFIG_ID} and trace its response handling. Check how the configuration's modification time can be represented as an HTTP Last-Modified header, using the telegraf watcher reference in cmd/telegraf/telegraf.go for expected behavior. Done means the endpoint returns a valid Last-Modified header so telegraf can detect configuration changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, database
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100