Skip to content

Commit

Permalink
update automatically settting gomemlimit (#1188)
Browse files Browse the repository at this point in the history
* update automatically settting gomemlimit

* update doc

* Update changelog for v1.2.1.

* Update docs

* Update docs/sources/reference/cli/environment-variables.md

Co-authored-by: Clayton Cornell <[email protected]>

* Update docs/sources/reference/cli/environment-variables.md

Co-authored-by: Clayton Cornell <[email protected]>

* Update docs/sources/reference/cli/environment-variables.md

Co-authored-by: Clayton Cornell <[email protected]>

* Update docs/sources/reference/cli/environment-variables.md

Co-authored-by: Clayton Cornell <[email protected]>

* fix typo

---------

Co-authored-by: Clayton Cornell <[email protected]>
  • Loading branch information
mattdurham and clayton-cornell authored Oct 30, 2024
1 parent 1c2ec56 commit 282005f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 26 deletions.
29 changes: 24 additions & 5 deletions docs/sources/reference/cli/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@ The following environment variables are supported:
* `HTTP_PROXY`
* `PPROF_MUTEX_PROFILING_PERCENT`
* `PPROF_BLOCK_PROFILING_RATE`
* `GOMEMLIMIT`


Refer to the [Go runtime][runtime] documentation for more information about Go runtime environment variables.

## GODEBUG

You can use the `GODEBUG` environment variable to control the debugging variables within the Go runtime. The following arguments are supported.

Argument | Description | Default
--------------------------------|------------------------------------------------------------------------------------------------------|--------
`x509usefallbackroots` | Enforce a fallback on the X.509 trusted root certificates. Set to `1` to enable. | `0`
`netdns` | Force a resolver. Set to `go` for a pure Go resolver. Set to `cgo` or `win32` for a native resolver. |
`netdns` | Show resolver debugging information. Set to `1` for basic information. Set to `2` for verbose. |
Argument | Description | Default
------------------------|------------------------------------------------------------------------------------------------------|---------
`x509usefallbackroots` | Enforce a fallback on the X.509 trusted root certificates. Set to `1` to enable. | `0`
`netdns` | Force a resolver. Set to `go` for a pure Go resolver. Set to `cgo` or `win32` for a native resolver. |
`netdns` | Show resolver debugging information. Set to `1` for basic information. Set to `2` for verbose. |

## HTTP_PROXY

Expand All @@ -45,4 +47,21 @@ You can use the `PPROF_BLOCK_PROFILING_RATE` environment variable to define the
* `1`: All mutexes are tracked.
* A value greater than `1`: The number of nanoseconds to track mutexes.

### GOMEMLIMIT

Usually, the [Go runtime][runtime] will release memory back to the operating system when requested.
In some environments, this may cause issues such as Out Of Memory (OOM) errors.
You can use the `GOMEMLIMIT` environment variable to set a soft memory cap and limit the maximum memory {{< param "PRODUCT_NAME" >}} can use.
You can set `GOMEMLIMIT` to a numeric value in bytes with an optional unit suffix.
The supported unit suffixes are `B`, `KiB`, `MiB`, `GiB`, and `TiB`.
Don't treat the `GOMEMLIMIT` environment variable as a hard memory limit.
{{< param "PRODUCT_NAME" >}} processes can use more memory if that memory is required.
A rough number is to set `GOMEMLIMIT` to is 90% of the maximum memory required.
For example, if you want to keep memory usage below `10GiB`, use `GOMEMLIMIT=9GiB`.

#### Automatically set GOMEMLIMIT

The `GOMEMLIMIT` environment variable is either automatically set to 90% of an available `cgroup` value, or you can explicitly set the `GOMEMLIMIT` environment variable before you run {{< param "PRODUCT_NAME" >}}.
No changes will occur if the limit cannot be determined and you did not explicitly define a `GOMEMLIMIT` value.

[runtime]: https://pkg.go.dev/runtime
1 change: 0 additions & 1 deletion docs/sources/reference/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ original configuration.
Include `--config.extra-args` to pass additional command line flags from the original format to the converter.
Refer to [alloy convert][] for more details on how `extra-args` work.


[alloy convert]: ../convert/
[clustering]: ../../../get-started/clustering/
[go-discover]: https://github.com/hashicorp/go-discover
Expand Down
4 changes: 1 addition & 3 deletions internal/alloycli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ func (fr *alloyRun) Run(configPath string) error {

// Set the memory limit, this will honor GOMEMLIMIT if set
// If there is a cgroup will follow that
if fr.minStability.Permits(featuregate.StabilityPublicPreview) {
memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.New(l.Handler())))
}
memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.New(l.Handler())))

// Enable the profiling.
setMutexBlockProfiling(l)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//go:build !freebsd


package datadog_config_test

import (
Expand Down
5 changes: 2 additions & 3 deletions internal/component/otelcol/exporter/datadog/datadog_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//go:build !freebsd


package datadog_test

import (
Expand Down Expand Up @@ -47,8 +46,8 @@ func TestConfigConversion(t *testing.T) {
defaultClient = confighttp.ClientConfig{
Timeout: defaultTimeout,
}
connsPerHost = 10
connsPerHostPtr = &connsPerHost
connsPerHost = 10
connsPerHostPtr = &connsPerHost
)

tests := []struct {
Expand Down
10 changes: 5 additions & 5 deletions internal/component/prometheus/exporter/oracledb/oracledb.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ var (

// Arguments controls the oracledb exporter.
type Arguments struct {
ConnectionString alloytypes.Secret `alloy:"connection_string,attr"`
MaxIdleConns int `alloy:"max_idle_conns,attr,optional"`
MaxOpenConns int `alloy:"max_open_conns,attr,optional"`
QueryTimeout int `alloy:"query_timeout,attr,optional"`
CustomMetrics alloytypes.OptionalSecret `alloy:"custom_metrics,attr,optional"`
ConnectionString alloytypes.Secret `alloy:"connection_string,attr"`
MaxIdleConns int `alloy:"max_idle_conns,attr,optional"`
MaxOpenConns int `alloy:"max_open_conns,attr,optional"`
QueryTimeout int `alloy:"query_timeout,attr,optional"`
CustomMetrics alloytypes.OptionalSecret `alloy:"custom_metrics,attr,optional"`
}

// SetToDefault implements syntax.Defaulter.
Expand Down
10 changes: 5 additions & 5 deletions internal/component/prometheus/exporter/oracledb/oracledb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ func TestArgumentsValidate(t *testing.T) {
{
name: "valid OracleDB",
args: Arguments{
ConnectionString: alloytypes.Secret("oracle://user:password@localhost:1521/orcl.localnet"),
MaxIdleConns: 1,
MaxOpenConns: 1,
QueryTimeout: 5,
ConnectionString: alloytypes.Secret("oracle://user:password@localhost:1521/orcl.localnet"),
MaxIdleConns: 1,
MaxOpenConns: 1,
QueryTimeout: 5,
CustomMetrics: alloytypes.OptionalSecret{
Value: `metrics:
- context: "slow_queries"
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestConvertNoCustom(t *testing.T) {
MaxIdleConns: DefaultArguments.MaxIdleConns,
MaxOpenConns: DefaultArguments.MaxOpenConns,
QueryTimeout: DefaultArguments.QueryTimeout,
CustomMetrics: "",
CustomMetrics: "",
}
require.Equal(t, expected, *res)
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Config struct {
QueryTimeout int `yaml:"query_timeout"`
CustomMetrics string `yaml:"custom_metrics,omitempty"`
}

// ValidateConnString attempts to ensure the connection string supplied is valid
// to connect to an OracleDB instance
func validateConnString(connStr string) error {
Expand Down Expand Up @@ -102,9 +103,9 @@ func New(logger log.Logger, c *Config) (integrations.Integration, error) {
}

oeExporter, err := oe.NewExporter(logger, &oe.Config{
DSN: string(c.ConnectionString),
MaxIdleConns: c.MaxIdleConns,
MaxOpenConns: c.MaxOpenConns,
DSN: string(c.ConnectionString),
MaxIdleConns: c.MaxIdleConns,
MaxOpenConns: c.MaxOpenConns,
CustomMetrics: c.CustomMetrics,
QueryTimeout: c.QueryTimeout,
})
Expand Down

0 comments on commit 282005f

Please sign in to comment.