Skip to content

Commit

Permalink
Adapt SNMP flow component/integration to new SNMP exporter config cha…
Browse files Browse the repository at this point in the history
…nges (#4265)
  • Loading branch information
marctc authored Jul 4, 2023
1 parent a2226c1 commit 6710bda
Show file tree
Hide file tree
Showing 19 changed files with 49,540 additions and 53,680 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ internal API changes are not present.
Main (unreleased)
-----------------

> **BREAKING CHANGES**: This release has breaking changes. Please read entries
> carefully and consult the [upgrade guide][] for specific instructions.
### Breaking changes

- The algorithm for the "hash" action of `otelcol.processor.attributes` has changed.
Expand All @@ -20,6 +23,8 @@ Main (unreleased)
- `otelcol.extension.jaeger_remote_sampling` removes the `\` HTTP endpoint. The `/sampling` endpoint is still functional.
The change was made in PR [#18070](https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/18070) of opentelemetry-collector-contrib. (@ptodev)

- The field `version` and `auth` struct block from `walk_params` in `prometheus.exporter.snmp` and SNMP integration have been removed. The auth block now can be configured at top level, together with `modules` (@marctc)

### Features

- The Pyroscope scrape component computes and sends delta profiles automatically when required to reduce bandwidth usage. (@cyriltovena)
Expand Down Expand Up @@ -81,6 +86,9 @@ Main (unreleased)

- Allow setting the node name for clustering with a command-line flag. (@tpaschalis)

- Allow `prometheus.exporter.snmp` and SNMP integration to be configured passing a YAML block. (@marctc)


### Bugfixes

- Add signing region to remote.s3 component for use with custom endpoints so that Authorization Headers work correctly when
Expand Down
68 changes: 34 additions & 34 deletions component/prometheus/exporter/snmp/snmp.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package snmp

import (
"errors"
"fmt"
"time"

"github.com/grafana/agent/component"
"github.com/grafana/agent/component/discovery"
"github.com/grafana/agent/component/prometheus/exporter"
"github.com/grafana/agent/pkg/integrations"
"github.com/grafana/agent/pkg/integrations/snmp_exporter"
"github.com/grafana/agent/pkg/river/rivertypes"
snmp_config "github.com/prometheus/snmp_exporter/config"
"gopkg.in/yaml.v2"
)

func init() {
Expand Down Expand Up @@ -45,6 +47,9 @@ func buildSNMPTargets(baseTarget discovery.Target, args component.Arguments) []d
if tgt.WalkParams != "" {
target["__param_walk_params"] = tgt.WalkParams
}
if tgt.Auth != "" {
target["__param_auth"] = tgt.Auth
}

targets = append(targets, target)
}
Expand All @@ -57,6 +62,7 @@ type SNMPTarget struct {
Name string `river:",label"`
Target string `river:"address,attr"`
Module string `river:"module,attr,optional"`
Auth string `river:"auth,attr,optional"`
WalkParams string `river:"walk_params,attr,optional"`
}

Expand All @@ -70,44 +76,18 @@ func (t TargetBlock) Convert() []snmp_exporter.SNMPTarget {
Name: target.Name,
Target: target.Target,
Module: target.Module,
Auth: target.Auth,
WalkParams: target.WalkParams,
})
}
return targets
}

type Auth struct {
Community rivertypes.Secret `river:"community,attr,optional"`
SecurityLevel string `river:"security_level,attr,optional"`
Username string `river:"username,attr,optional"`
Password rivertypes.Secret `river:"password,attr,optional"`
AuthProtocol string `river:"auth_protocol,attr,optional"`
PrivProtocol string `river:"priv_protocol,attr,optional"`
PrivPassword rivertypes.Secret `river:"priv_password,attr,optional"`
ContextName string `river:"context_name,attr,optional"`
}

// Convert converts the component's Auth to the integration's Auth.
func (a Auth) Convert() snmp_config.Auth {
return snmp_config.Auth{
Community: snmp_config.Secret(a.Community),
SecurityLevel: a.SecurityLevel,
Username: a.Username,
Password: snmp_config.Secret(a.Password),
AuthProtocol: a.AuthProtocol,
PrivProtocol: a.PrivProtocol,
PrivPassword: snmp_config.Secret(a.PrivPassword),
ContextName: a.ContextName,
}
}

type WalkParam struct {
Name string `river:",label"`
Version int `river:"version,attr,optional"`
MaxRepetitions uint32 `river:"max_repetitions,attr,optional"`
Retries int `river:"retries,attr,optional"`
Timeout time.Duration `river:"timeout,attr,optional"`
Auth Auth `river:"auth,block,optional"`
UseUnconnectedUDPSocket bool `river:"use_unconnected_udp_socket,attr,optional"`
}

Expand All @@ -118,21 +98,40 @@ func (w WalkParams) Convert() map[string]snmp_config.WalkParams {
walkParams := make(map[string]snmp_config.WalkParams)
for _, walkParam := range w {
walkParams[walkParam.Name] = snmp_config.WalkParams{
Version: walkParam.Version,
MaxRepetitions: walkParam.MaxRepetitions,
Retries: walkParam.Retries,
Retries: &walkParam.Retries,
Timeout: walkParam.Timeout,
Auth: walkParam.Auth.Convert(),
UseUnconnectedUDPSocket: walkParam.UseUnconnectedUDPSocket,
}
}
return walkParams
}

type Arguments struct {
ConfigFile string `river:"config_file,attr"`
Targets TargetBlock `river:"target,block"`
WalkParams WalkParams `river:"walk_param,block,optional"`
ConfigFile string `river:"config_file,attr,optional"`
Config string `river:"config,attr,optional"`
Targets TargetBlock `river:"target,block"`
WalkParams WalkParams `river:"walk_param,block,optional"`
ConfigStruct snmp_config.Config
}

// UnmarshalRiver implements River unmarshalling for Arguments.
func (a *Arguments) UnmarshalRiver(f func(interface{}) error) error {
type args Arguments
if err := f((*args)(a)); err != nil {
return err
}

if a.ConfigFile != "" && a.Config != "" {
return errors.New("config and config_file are mutually exclusive")
}

err := yaml.UnmarshalStrict([]byte(a.Config), &a.ConfigStruct)
if err != nil {
return fmt.Errorf("invalid snmp_exporter config: %s", err)
}

return nil
}

// Convert converts the component's Arguments to the integration's Config.
Expand All @@ -141,5 +140,6 @@ func (a *Arguments) Convert() *snmp_exporter.Config {
SnmpConfigFile: a.ConfigFile,
SnmpTargets: a.Targets.Convert(),
WalkParams: a.WalkParams.Convert(),
SnmpConfig: a.ConfigStruct,
}
}
Loading

0 comments on commit 6710bda

Please sign in to comment.