in extension/apmconfigextension/elastic/centralconfig/fetcher.go [48:84]
func (fw *fetcherAPMWatcher) RemoteConfig(ctx context.Context, agentUid apmconfig.InstanceUid, agentAttrs apmconfig.IdentifyingAttributes) (*protobufs.AgentRemoteConfig, error) {
var serviceParams agentcfg.Service
for _, attr := range agentAttrs {
switch attr.GetKey() {
case string(semconv.ServiceNameKey):
serviceParams.Name = attr.GetValue().GetStringValue()
case string(semconv.DeploymentEnvironmentNameKey):
serviceParams.Environment = attr.GetValue().GetStringValue()
}
}
if serviceParams.Name == "" {
return nil, fmt.Errorf("%w: service.name attribute must be provided", apmconfig.UnidentifiedAgent)
}
result, err := fw.configFetcher.Fetch(ctx, agentcfg.Query{
Service: serviceParams,
})
if err != nil {
return nil, err
} else if len(result.Source.Settings) == 0 {
return nil, nil
}
marshallConfig, err := json.Marshal(result.Source.Settings)
if err != nil {
return nil, err
}
return &protobufs.AgentRemoteConfig{ConfigHash: []byte(result.Source.Etag), Config: &protobufs.AgentConfigMap{
ConfigMap: map[string]*protobufs.AgentConfigFile{
"": {
Body: marshallConfig,
ContentType: configContentType,
},
},
}}, nil
}