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 User-Agent header and documentation #34

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,14 @@ remote_read:
The Prometheus Connector will use the default credentials provider implemented in the AWS SDK for Go instead of allowing users
to provide the credentials through command-line flags. This prevents sensitive data from being easily scraped.

## User-Agent Header

The Prometheus Connector uses the following `User-Agent` header for all requests:

```
User-Agent: Prometheus Connector/<version> aws-sdk-go/<version> (go<version>; <os>; <cpu arch>)
```

# Developer Documentation

## Building the Prometheus Connector from Source
Expand Down
8 changes: 8 additions & 0 deletions timestream/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/timestreamquery"
"github.com/aws/aws-sdk-go/service/timestreamquery/timestreamqueryiface"
Expand All @@ -41,19 +42,26 @@ import (
type labelOperation string
type longMetricsOperation func(measureValueName string) (labelOperation, error)

var addUserAgent = request.NamedHandler {
Name: "UserAgentHandler",
Fn: request.MakeAddToUserAgentHandler("Prometheus Connector", Version),
}

// Store the initialization function calls to allow unit tests to mock the creation of real clients.
var initWriteClient = func(config *aws.Config) (timestreamwriteiface.TimestreamWriteAPI, error) {
sess, err := session.NewSession(config)
if err != nil {
return nil, err
}
sess.Handlers.Build.PushFrontNamed(addUserAgent)
return timestreamwrite.New(sess), nil
}
var initQueryClient = func(config *aws.Config) (timestreamqueryiface.TimestreamQueryAPI, error) {
sess, err := session.NewSession(config)
if err != nil {
return nil, err
}
sess.Handlers.Build.PushFrontNamed(addUserAgent)
return timestreamquery.New(sess), nil
}

Expand Down