in translator/translate/otel/receiver/jmx/translator.go [84:184]
func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
if conf == nil || !conf.IsSet(common.JmxConfigKey) {
return nil, &common.MissingKeyError{ID: t.ID(), JsonKey: common.JmxConfigKey}
}
cfg := t.factory.CreateDefaultConfig().(*jmxreceiver.Config)
jmxMap := common.GetIndexedMap(conf, common.JmxConfigKey, t.index)
cfg.JARPath = paths.JMXJarPath
if jarPath := os.Getenv(envJmxJarPath); jarPath != "" {
cfg.JARPath = jarPath
}
if endpoint, ok := jmxMap[common.Endpoint].(string); ok {
cfg.Endpoint = endpoint
} else {
return nil, errNoEndpoint
}
var targetSystems []string
for _, jmxTarget := range common.JmxTargets {
if _, ok := jmxMap[jmxTarget]; ok {
targetSystems = append(targetSystems, jmxTarget)
}
}
if len(targetSystems) == 0 {
return nil, errNoTargetSystems
}
cfg.TargetSystem = strings.Join(targetSystems, ",")
// Prioritize metric collection internal in JMX section, then agent section
// Setting default to 10 seconds which is used by OTEL as well
intervalKeyChain := []string{
common.ConfigKey(common.AgentKey, common.MetricsCollectionIntervalKey),
}
cfg.CollectionInterval = common.GetOrDefaultDuration(conf, intervalKeyChain, defaultCollectionInterval)
collectionInterval, err := common.ParseDuration(jmxMap[common.MetricsCollectionIntervalKey])
if err == nil {
cfg.CollectionInterval = collectionInterval
}
if username, ok := jmxMap[usernameKey].(string); ok {
cfg.Username = username
}
if passwordFile, ok := jmxMap[passwordFileKey].(string); ok {
cfg.PasswordFile = passwordFile
}
if keystorePath, ok := jmxMap[keystorePathKey].(string); ok {
cfg.KeystorePath = keystorePath
}
if keystoreType, ok := jmxMap[keystoreTypeKey].(string); ok {
cfg.KeystoreType = keystoreType
}
if truststorePath, ok := jmxMap[truststorePathKey].(string); ok {
cfg.TruststorePath = truststorePath
}
if registrySSLEnabled, ok := jmxMap[registrySSLEnabledKey].(bool); ok {
cfg.JMXRegistrySSLEnabled = registrySSLEnabled
}
if truststoreType, ok := jmxMap[truststoreTypeKey].(string); ok {
cfg.TruststoreType = truststoreType
}
if remoteProfile, ok := jmxMap[remoteProfileKey].(string); ok {
cfg.RemoteProfile = remoteProfile
}
if realm, ok := jmxMap[realmKey].(string); ok {
cfg.Realm = realm
}
cfg.ResourceAttributes = make(map[string]string)
if appendDimensions, ok := jmxMap[common.AppendDimensionsKey].(map[string]any); ok {
c := confmap.NewFromStringMap(appendDimensions)
if err = c.Unmarshal(&cfg.ResourceAttributes); err != nil {
return nil, fmt.Errorf("unable to unmarshal %s: %w", common.ConfigKey(common.JmxConfigKey, common.AppendDimensionsKey), err)
}
}
if !context.CurrentContext().GetOmitHostname() && !conf.IsSet(ec2taggerprocessor.Ec2taggerKey) {
hostname, err := os.Hostname()
if err != nil {
log.Printf("E! error finding hostname for jmx metrics %v", err)
} else {
cfg.ResourceAttributes[attributeHost] = hostname
}
}
var skipAuthValidation bool
if insecure, ok := jmxMap[common.InsecureKey].(bool); ok {
skipAuthValidation = insecure
}
return cfg, validate(cfg, skipAuthValidation)
}