Skip to content

Commit e1ef2f3

Browse files
committed
fix version
1 parent e1b16dc commit e1ef2f3

File tree

8 files changed

+107
-21
lines changed

8 files changed

+107
-21
lines changed

src/core/config/config.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"io/fs"
1717
"os"
1818
"path/filepath"
19+
"reflect"
20+
"sort"
1921
"strings"
2022
"sync"
2123
"time"
@@ -254,6 +256,7 @@ func UpdateAgentConfig(systemId string, updateTags []string, updateFeatures []st
254256
log.Errorf("Failed to register config: %v", err)
255257
return false, err
256258
}
259+
257260
// Update nil valued updateTags to empty slice for comparison
258261
if updateTags == nil {
259262
updateTags = []string{}
@@ -263,12 +266,33 @@ func UpdateAgentConfig(systemId string, updateTags []string, updateFeatures []st
263266
updateFeatures = []string{}
264267
}
265268

269+
// Sort tags and compare them
270+
sort.Strings(updateTags)
271+
sort.Strings(config.Tags)
272+
synchronizedTags := reflect.DeepEqual(updateTags, config.Tags)
273+
266274
Viper.Set(TagsKey, updateTags)
267275
config.Tags = Viper.GetStringSlice(TagsKey)
268276

277+
// Needed for legacy reasons.
278+
// Remove Features_ prefix from the feature strings.
279+
// This is needed for management servers that are sending features before sdk version v2.23.0
280+
for index, feature := range updateFeatures {
281+
updateFeatures[index] = strings.Replace(feature, "features_", "", 1)
282+
}
283+
sort.Strings(updateFeatures)
284+
sort.Strings(config.Features)
285+
synchronizedFeatures := reflect.DeepEqual(updateFeatures, config.Features)
286+
269287
Viper.Set(agent_config.FeaturesKey, updateFeatures)
270288
config.Features = Viper.GetStringSlice(agent_config.FeaturesKey)
271289

290+
// If the features are already synchronized there is no need to overwrite
291+
if synchronizedTags && synchronizedFeatures {
292+
log.Debug("Manager and Local tags and features are already synchronized")
293+
return false, nil
294+
}
295+
272296
// Get the dynamic config path and use default dynamic config path if it's not
273297
// already set.
274298
dynamicCfgPath := Viper.GetString(DynamicConfigPathKey)

src/core/config/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func TestUpdateAgentConfig(t *testing.T) {
417417
updatedConfFeatures: curConf.Features,
418418
expConfTags: curConf.Tags,
419419
expConfFeatures: curConf.Features,
420-
updatedConf: true,
420+
updatedConf: false,
421421
},
422422
{
423423
testName: "UpdatedTags",
@@ -458,7 +458,7 @@ func TestUpdateAgentConfig(t *testing.T) {
458458
// Attempt update & check results
459459
updated, err := UpdateAgentConfig("12345", tc.updatedConfTags, tc.updatedConfFeatures)
460460
assert.NoError(t, err)
461-
assert.Equal(t, tc.updatedConf, updated)
461+
assert.Equal(t, updated, tc.updatedConf)
462462

463463
// Get potentially updated config
464464
updatedConf, err := GetConfig("12345")

src/plugins/config_reader.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (r *ConfigReader) updateAgentConfig(payloadAgentConfig *proto.AgentConfig)
100100
}
101101

102102
synchronizeFeatures := false
103+
synchronizeTags := false
103104

104105
if payloadAgentConfig.Details.Features != nil {
105106
r.detailsMu.Lock()
@@ -127,14 +128,20 @@ func (r *ConfigReader) updateAgentConfig(payloadAgentConfig *proto.AgentConfig)
127128
r.detailsMu.Unlock()
128129
}
129130

130-
tags := payloadAgentConfig.Details.Tags
131-
features := payloadAgentConfig.Details.Features
132-
configUpdated, err := config.UpdateAgentConfig(r.config.ClientID, tags, features)
133-
if err != nil {
134-
log.Errorf("Failed updating Agent config - %v", err)
135-
}
136-
if configUpdated {
137-
log.Debugf("Updated agent config on disk")
131+
sort.Strings(onDiskAgentConfig.Tags)
132+
sort.Strings(payloadAgentConfig.Details.Tags)
133+
synchronizeTags = !reflect.DeepEqual(payloadAgentConfig.Details.Tags, onDiskAgentConfig.Tags)
134+
135+
if synchronizeFeatures || synchronizeTags {
136+
tags := payloadAgentConfig.Details.Tags
137+
features := payloadAgentConfig.Details.Features
138+
configUpdated, err := config.UpdateAgentConfig(r.config.ClientID, tags, features)
139+
if err != nil {
140+
log.Errorf("Failed updating Agent config - %v", err)
141+
}
142+
if configUpdated {
143+
log.Debugf("Updated agent config on disk")
144+
}
138145
}
139146

140147
if payloadAgentConfig.Details.Extensions != nil {

src/plugins/dataplane_status_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func TestDPSSyncAgentConfigChange(t *testing.T) {
239239
Tags: tutils.InitialConfTags,
240240
Features: config.Defaults.Features,
241241
},
242-
updatedTags: true,
242+
updatedTags: false,
243243
},
244244
}
245245
processID := "12345"
@@ -288,7 +288,7 @@ func TestDPSSyncAgentConfigChange(t *testing.T) {
288288
// Attempt update & check results
289289
updated, err := config.UpdateAgentConfig("12345", tc.expUpdatedConfig.Tags, tc.expUpdatedConfig.Features)
290290
assert.Nil(t, err)
291-
assert.Equal(t, tc.updatedTags, updated)
291+
assert.Equal(t, updated, tc.updatedTags)
292292

293293
// Create message that should trigger a sync agent config call
294294
msg := core.NewMessage(core.AgentConfigChanged, "")

src/plugins/metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func TestMetrics_Process_AgentConfigChanged(t *testing.T) {
229229
},
230230
Features: config.Defaults.Features,
231231
},
232-
updatedTags: true,
232+
updatedTags: false,
233233
},
234234
}
235235

test/integration/vendor/github.com/nginx/agent/v2/src/core/config/config.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/performance/vendor/github.com/nginx/agent/v2/src/core/config/config.go

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/performance/vendor/github.com/nginx/agent/v2/src/plugins/config_reader.go

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)