Skip to content

Commit

Permalink
Add User-Agent header and documentation (awslabs#34)
Browse files Browse the repository at this point in the history
* Add User-Agent documentation to README

* Add User-Agent header value

---------

Co-authored-by: Trevor Bonas <[email protected]>
  • Loading branch information
2 people authored and forestmvey committed May 7, 2024
1 parent 4564d8f commit 2225d4d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
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

0 comments on commit 2225d4d

Please sign in to comment.