Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(): Additional parsing of jmx target parameters #35

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions metricbeat/mb/lightmetricset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package mb

import (
"github.com/pkg/errors"

Check failure on line 21 in metricbeat/mb/lightmetricset.go

View workflow job for this annotation

GitHub Actions / lint (windows)

import of package `github.com/pkg/errors` is blocked because the module is in the blocked modules list. `errors` and `fmt` are recommended modules. This package is deprecated, use `fmt.Errorf` with `%!w(MISSING)` instead. (gomodguard)

Check failure on line 21 in metricbeat/mb/lightmetricset.go

View workflow job for this annotation

GitHub Actions / lint (linux)

import of package `github.com/pkg/errors` is blocked because the module is in the blocked modules list. `errors` and `fmt` are recommended modules. This package is deprecated, use `fmt.Errorf` with `%!w(MISSING)` instead. (gomodguard)

Check failure on line 21 in metricbeat/mb/lightmetricset.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

import of package `github.com/pkg/errors` is blocked because the module is in the blocked modules list. `errors` and `fmt` are recommended modules. This package is deprecated, use `fmt.Errorf` with `%!w(MISSING)` instead. (gomodguard)

"github.com/elastic/beats/v7/libbeat/processors"
conf "github.com/elastic/elastic-agent-libs/config"
Expand Down Expand Up @@ -113,6 +113,12 @@
return nil, errors.Wrap(err, "failed to copy values from user configuration")
}

// Process jmx target params
rawConfig, err = processJmxTarget(rawConfig)
if err != nil {
return nil, errors.Wrap(err, "process jmx target params error")
}

// Create the base module
baseModule, err := newBaseModuleFromConfig(rawConfig)
if err != nil {
Expand All @@ -122,3 +128,36 @@

return &baseModule, nil
}

func processJmxTarget(rawConfig *conf.C) (*conf.C, error) {
if !rawConfig.HasField("jmx") || !rawConfig.HasField("jmx_target") {
return rawConfig, nil
}

cfgMap := map[string]interface{}{}
if err := rawConfig.Unpack(&cfgMap); err != nil {
return rawConfig, errors.Wrap(err, "failed to converting config to map")
}

if _, ok := cfgMap["jmx_target"].(map[string]interface{}); !ok {
return rawConfig, nil
}
jmxTarget := cfgMap["jmx_target"]

if jmx, ok := cfgMap["jmx"].(map[string]interface{}); ok {
if mappings, ok1 := jmx["mappings"].([]interface{}); ok1 {
for _, mapping := range mappings {
if _, ok2 := mapping.(map[string]interface{}); ok2 {
mapping.(map[string]interface{})["target"] = jmxTarget
}
}
}
}

newConfig, err := conf.NewConfigFrom(cfgMap)
if err != nil {
return rawConfig, errors.Wrap(err, "failed to copy values from user configuration")
}

return newConfig, nil
}
Loading