feat: Add Cloud Run Output Plugin & Update to Wavefront Serializer#10210
feat: Add Cloud Run Output Plugin & Update to Wavefront Serializer#10210crflanigan wants to merge 20 commits intoinfluxdata:masterfrom homedepot:master
Conversation
Development
Auth.go Test Case Changes Great work @zachmares !!
- tweak function and argument names - cleaned up comments, new lines - adjust TestGetAccessToken test case
- added some TODOs for further strengthening of test cases, but established testing pattern.
- Close() and Connect() are called inside Write() and are required to have no error - Adjust TODO
|
Thanks so much for the pull request! |
|
Thanks so much for the pull request! |
|
!signed-cla |
|
📦 Looks like new artifacts were built from this PR. Expand this list to get them here ! 🐯Artifact URLs |
There was a problem hiding this comment.
@crflanigan thank you very much for this cool contribution! The linter found some issues and I also have some comments in the code. The most severe ones are
- Please split this PR into one for the Wavefront part and one for the CloudRun part. You probably best move the Wavefront part to a new PR and remove it from this one. Please remember to adapt the PR title and description accordingly. Feel free to assign (or mention) me in the newly created PR so I can give it a review.
- Almost half of the PR goes to
common/gcpdealing with the authentication. I wonder why you can't use the existing oauth2 library. Is there a reason? If you really can't use any external lib, my impression is thatcommon/gcpshould be a library outside of Telegraf as it is in no way specific to this project. - Please check the linter warnings and errors.
Looking forward to the next round and your comments!
| // Skip inputs that are registered twice for backward compatibility | ||
| if pname == "cisco_telemetry_gnmi" { | ||
| continue | ||
| } | ||
| if pname == "KNXListener" { | ||
| continue | ||
| } |
|
|
||
| require github.com/libp2p/go-reuseport v0.1.0 | ||
| require ( | ||
| github.com/golang-jwt/jwt v3.2.2+incompatible |
There was a problem hiding this comment.
Would it be possible to use github.com/golang-jwt/jwt/v4 which we already carry as a dependency instead of v3?
There was a problem hiding this comment.
Let me check, thank you!
| @@ -0,0 +1,118 @@ | |||
| package gcp | |||
There was a problem hiding this comment.
Why do you put this in common? The only user currently AFAICS is cloutrun, so it belongs there. If you plan to add more users later we can still move the files...
There was a problem hiding this comment.
Sure, would you suggest (if we keep this package) we keep this code alongside the cloudrun package code?
There was a problem hiding this comment.
Kind of. First of all, please check carefully if using golang.org/x/oauth2/google is an option instead of really having this code. Second, I tend to making the code in this package an external packages that does not live in telegraf. However, if you have good reasons why option one and two cannot be pursued we should move it to the cloudrun plugin directory.
| return "", fmt.Errorf("could not parse service account JSON: %v", err) | ||
| } | ||
|
|
||
| signedJWT, err := generateSignedJWT(conf, audience, 120) |
There was a problem hiding this comment.
Is that expiry time the only valid value? Maybe you should allow to provide the expiry time as a parameter.
| func generateSignedJWT(conf *jwt.Config, audience string, expiryLength int64) (string, error) { | ||
| now := time.Now().Unix() |
There was a problem hiding this comment.
To be honest I would feel a bit better to get the expiry time as a time.Duration...
| func generateSignedJWT(conf *jwt.Config, audience string, expiryLength int64) (string, error) { | |
| now := time.Now().Unix() | |
| func generateSignedJWT(conf *jwt.Config, audience string, expiryLength time.Duration) (string, error) { | |
| now := time.Now().Unix() | |
| expiry := now.Add(expiryLength) |
| req.Header.Set("Content-Type", defaultContentType) | ||
| req.Header.Set("Accept", defaultAccept) |
There was a problem hiding this comment.
Please directly set the values here instead of using default... constants as this is the only user and you directly can see what is set instead of navigating the whole file.
| if strings.ToLower(k) == "host" { | ||
| req.Host = v | ||
| } |
There was a problem hiding this comment.
Do you mean to continue here as otherwise host is set twice once in req.Host and another time as req.Header...
| } | ||
|
|
||
| if resp.StatusCode < 200 || resp.StatusCode >= 300 { | ||
| return fmt.Errorf("when writing to [%s] received status code: %d", cr.URL, resp.StatusCode) |
There was a problem hiding this comment.
| return fmt.Errorf("when writing to [%s] received status code: %d", cr.URL, resp.StatusCode) | |
| return fmt.Errorf("when writing to %q received status code: %d", cr.URL, resp.StatusCode) |
| PrometheusStringAsLabel bool `toml:"prometheus_string_as_label"` | ||
|
|
||
| // Convert "_" in paths to "." for Wavefront | ||
| WavefrontConvertPaths bool `toml:"convert_paths"` |
There was a problem hiding this comment.
With this change you will break all existing wavefront users as suddenly (when using their old config) their paths change without further notice on updateing telegraf. This cannot happen. Please invert that setting such that by default (i.e. not set by the user) the paths are converted as before.
A natural alternative would be wavefront_keep_path or wavefront_disable_path_conversion.
| } | ||
|
|
||
| s := WavefrontSerializer{} | ||
| s := WavefrontSerializer{ConvertPaths: true} |
There was a problem hiding this comment.
That's exactly the point mentioned above. All current users would need to do the same in their config. Please keep existing tests unchanged to ensure backward compatibility!
There was a problem hiding this comment.
Good point!
Let me fix that.
|
Going to close this as suggested by @srebhan and open two pull requests, one for the update to the Wavefront serializer and one for the Cloud Run code. |
Required for all PRs:
resolves #7913
Added an output plugin for Google Cloud Run which implements the OAuth 2.0 protocol enabling the Telegraf agent to send encrypted metric payloads into a time series metrics proxy running in GCP.
Additionally, customers using the Wavefront serializer who don't wish to have their metric prefixes modified may configure their output plugin in the same way as the Wavefront Output Plugin.
This is accomplished by adding the
convert_paths = falseboolean option to the output section of their conf file.Example prefix before getting processed by the Wavefront serializer:
prod.prefix_name.metric_nameExisting behavior:
prefix.name.metric.nameNew behavior with
convert_paths = falseoption:prod.prefix_name.metric_name