Skip to content

Commit

Permalink
Gcve useragent (#507)
Browse files Browse the repository at this point in the history
* added global variable userAgent to file

* added GCVE configurable variable userAgent

* updated to remove comment and change test string

* updated defaults for max entry and request size (#508)

* updated defaults for max entry and request size

* updated docs to new entry and request defaults

* updated to latest version of master, forgot to merge

* found duplicate variable userAgent
  • Loading branch information
armstrmi authored Dec 14, 2021
1 parent 9aec188 commit 019990f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion operator/builtin/output/googlecloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"google.golang.org/grpc/encoding/gzip"
)

var userAgent = "StanzaLogAgent"

const (
operatorType = "google_cloud_output"
loggingScope = "https://www.googleapis.com/auth/logging.write"
Expand Down Expand Up @@ -164,11 +166,15 @@ func (c GoogleCloudOutputConfig) getCredentials() (*google.Credentials, error) {
func (c GoogleCloudOutputConfig) createClientOptions(credentials *google.Credentials, useCompression bool) []option.ClientOption {
options := make([]option.ClientOption, 0, 2)
options = append(options, option.WithCredentials(credentials))
options = append(options, option.WithUserAgent("StanzaLogAgent/"+version.GetVersion()))
options = append(options, option.WithUserAgent(getUserAgent()))
if useCompression {
compressOption := option.WithGRPCDialOption(grpc.WithDefaultCallOptions(grpc.UseCompressor(gzip.Name)))
options = append(options, compressOption)
}

return options
}

func getUserAgent() string {
return fmt.Sprintf("%s/%s", userAgent, version.GetVersion())
}
7 changes: 7 additions & 0 deletions operator/builtin/output/googlecloud/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ import (
"github.com/observiq/stanza/operator/buffer"
"github.com/observiq/stanza/operator/helper"
"github.com/observiq/stanza/testutil"
"github.com/observiq/stanza/version"
"github.com/stretchr/testify/require"
)

func TestUserAgentVar(t *testing.T) {
require.Equal(t, getUserAgent(), "StanzaLogAgent/"+version.GetVersion())
userAgent = "TestAgent"
require.Equal(t, getUserAgent(), "TestAgent/"+version.GetVersion())
}

func TestInitHook(t *testing.T) {
builderFunc, ok := operator.DefaultRegistry.Lookup(operatorType)
require.True(t, ok)
Expand Down

0 comments on commit 019990f

Please sign in to comment.