Skip to content

Commit 8fd1e0a

Browse files
authored
fix: return empty remote configurations (#608)
1 parent eaaa6c1 commit 8fd1e0a

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
lines changed

extension/apmconfigextension/elastic/centralconfig/fetcher.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import (
2929
"go.uber.org/zap"
3030
)
3131

32-
const configContentType = "application/json"
33-
const configFileName = "elastic"
32+
const (
33+
configContentType = "application/json"
34+
configFileName = "elastic"
35+
)
3436

3537
var _ apmconfig.RemoteConfigClient = (*fetcherAPMWatcher)(nil)
3638

@@ -65,8 +67,6 @@ func (fw *fetcherAPMWatcher) RemoteConfig(ctx context.Context, agentUid apmconfi
6567
})
6668
if err != nil {
6769
return nil, err
68-
} else if len(result.Source.Settings) == 0 {
69-
return nil, nil
7070
}
7171

7272
marshallConfig, err := json.Marshal(result.Source.Settings)

extension/apmconfigextension/elastic/centralconfig/fetcher_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,35 @@ func TestRemoteConfig(t *testing.T) {
9999
},
100100
expectedError: nil,
101101
},
102+
"empty remote config for all services": {
103+
agentUid: apmconfig.InstanceUid("test-agent"),
104+
agentAttrs: apmconfig.IdentifyingAttributes{
105+
&protobufs.KeyValue{
106+
Key: "service.name",
107+
Value: &protobufs.AnyValue{Value: &protobufs.AnyValue_StringValue{StringValue: "dev"}},
108+
},
109+
},
110+
mockedFetchFn: func(context.Context, agentcfg.Query) (agentcfg.Result, error) {
111+
return agentcfg.Result{
112+
Source: agentcfg.Source{
113+
Etag: "-",
114+
Settings: agentcfg.Settings{},
115+
},
116+
}, nil
117+
},
118+
expectedRemoteConfig: &protobufs.AgentRemoteConfig{
119+
ConfigHash: []byte("-"),
120+
Config: &protobufs.AgentConfigMap{
121+
ConfigMap: map[string]*protobufs.AgentConfigFile{
122+
"elastic": {
123+
Body: []byte(`{}`),
124+
ContentType: "application/json",
125+
},
126+
},
127+
},
128+
},
129+
expectedError: nil,
130+
},
102131
"fetcher error": {
103132
agentUid: apmconfig.InstanceUid("test-agent"),
104133
agentAttrs: apmconfig.IdentifyingAttributes{

extension/apmconfigextension/integration_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,53 @@ func apmConfigintegrationTest(name string) func(t *testing.T) {
122122
},
123123
agentCfgIndexModifier: func(t *testing.T, client *elasticsearch.Client) {},
124124
},
125+
{
126+
name: "agent receives empty remote config",
127+
opampMessages: []inOutOpamp{
128+
{
129+
agentToServer: &protobufs.AgentToServer{
130+
InstanceUid: []byte("test"),
131+
AgentDescription: &protobufs.AgentDescription{
132+
IdentifyingAttributes: []*protobufs.KeyValue{
133+
{
134+
Key: "service.name",
135+
Value: &protobufs.AnyValue{Value: &protobufs.AnyValue_StringValue{StringValue: "test-agent-empty"}},
136+
},
137+
},
138+
},
139+
},
140+
expectedServerToAgent: &protobufs.ServerToAgent{
141+
InstanceUid: []byte("test"),
142+
Capabilities: uint64(protobufs.ServerCapabilities_ServerCapabilities_OffersRemoteConfig),
143+
RemoteConfig: &protobufs.AgentRemoteConfig{
144+
ConfigHash: []byte("-"),
145+
Config: &protobufs.AgentConfigMap{
146+
ConfigMap: map[string]*protobufs.AgentConfigFile{
147+
"elastic": {
148+
Body: []byte(`{}`),
149+
ContentType: "application/json",
150+
},
151+
},
152+
},
153+
},
154+
},
155+
},
156+
{
157+
agentToServer: &protobufs.AgentToServer{
158+
InstanceUid: []byte("test"),
159+
RemoteConfigStatus: &protobufs.RemoteConfigStatus{
160+
LastRemoteConfigHash: []byte("-"),
161+
Status: protobufs.RemoteConfigStatuses_RemoteConfigStatuses_APPLIED,
162+
},
163+
},
164+
expectedServerToAgent: &protobufs.ServerToAgent{
165+
InstanceUid: []byte("test"),
166+
Capabilities: uint64(protobufs.ServerCapabilities_ServerCapabilities_OffersRemoteConfig),
167+
},
168+
},
169+
},
170+
agentCfgIndexModifier: func(t *testing.T, client *elasticsearch.Client) {},
171+
},
125172
{
126173
name: "agent without config applies remote",
127174
opampMessages: []inOutOpamp{
@@ -287,6 +334,17 @@ func apmConfigintegrationTest(name string) func(t *testing.T) {
287334
expectedServerToAgent: &protobufs.ServerToAgent{
288335
InstanceUid: []byte("test-3"),
289336
Capabilities: uint64(protobufs.ServerCapabilities_ServerCapabilities_OffersRemoteConfig),
337+
RemoteConfig: &protobufs.AgentRemoteConfig{
338+
ConfigHash: []byte("-"),
339+
Config: &protobufs.AgentConfigMap{
340+
ConfigMap: map[string]*protobufs.AgentConfigFile{
341+
"elastic": {
342+
Body: []byte(`{}`),
343+
ContentType: "application/json",
344+
},
345+
},
346+
},
347+
},
290348
},
291349
},
292350
{
@@ -308,6 +366,17 @@ func apmConfigintegrationTest(name string) func(t *testing.T) {
308366
expectedServerToAgent: &protobufs.ServerToAgent{
309367
InstanceUid: []byte("test-3"),
310368
Capabilities: uint64(protobufs.ServerCapabilities_ServerCapabilities_OffersRemoteConfig),
369+
RemoteConfig: &protobufs.AgentRemoteConfig{
370+
ConfigHash: []byte("-"),
371+
Config: &protobufs.AgentConfigMap{
372+
ConfigMap: map[string]*protobufs.AgentConfigFile{
373+
"elastic": {
374+
Body: []byte(`{}`),
375+
ContentType: "application/json",
376+
},
377+
},
378+
},
379+
},
311380
},
312381
},
313382
{

0 commit comments

Comments
 (0)