Skip to content

Commit

Permalink
Merge pull request #1 from raphaelkox/max-samples-variable
Browse files Browse the repository at this point in the history
addded TransactionEvent.MaxSamplesStored as environment variable
  • Loading branch information
wedneyyuri authored Feb 7, 2022
2 parents ff58c31 + 220fa21 commit bfc108c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This plugin can be configured [through environment variables](https://github.com
- `NEW_RELIC_UTILIZATION_BILLING_HOSTNAME`: sets Utilization.BillingHostname
- `NEW_RELIC_UTILIZATION_LOGICAL_PROCESSORS`: sets Utilization.LogicalProcessors using [strconv.Atoi](https://golang.org/pkg/strconv/#Atoi).
- `NEW_RELIC_UTILIZATION_TOTAL_RAM_MIB`: sets Utilization.TotalRAMMIB using [strconv.Atoi](https://golang.org/pkg/strconv/#Atoi).
- `NEW_RELIC_TRANSACTION_EVENTS_MAX_SAMPLES_STORED`: sets TransactionEvents.MaxSamplesStored using [strconv.Atoi](https://golang.org/pkg/strconv/#Atoi).

## License

Expand Down
35 changes: 35 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package restqlnewrelic

import (
"fmt"
"os"
"strconv"

"github.com/newrelic/go-agent/v3/newrelic"
)

const transactionEventsMaxSamples = "NEW_RELIC_TRANSACTION_EVENTS_MAX_SAMPLES_STORED"

func ExtraConfigFromEnvironment() newrelic.ConfigOption {
return extraConfigFromEnvironment(os.Getenv)
}

func extraConfigFromEnvironment(getenv func(string) string) newrelic.ConfigOption {
return func(cfg *newrelic.Config) {
// Because fields could have been assigned in a previous
// ConfigOption, we only want to assign fields using environment
// variables that have been populated. This is especially
// relevant for the string case where no processing occurs.
assignInt := func(field *int, name string) {
if env := getenv(name); env != "" {
if i, err := strconv.Atoi(env); nil != err {
cfg.Error = fmt.Errorf("invalid %s value: %s", name, env)
} else {
*field = i
}
}
}

assignInt(&cfg.TransactionEvents.MaxSamplesStored, transactionEventsMaxSamples)
}
}
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ func init() {
}

func MakeNewRelicPlugin(logger restql.Logger) (restql.LifecyclePlugin, error) {
app, err := newrelic.NewApplication(newrelic.ConfigFromEnvironment())
app, err := newrelic.NewApplication(
newrelic.ConfigFromEnvironment(),
ExtraConfigFromEnvironment(),
)

if err != nil {
logger.Error("failed to initialize new relic", err)
Expand Down

0 comments on commit bfc108c

Please sign in to comment.