Skip to content

Commit 4a5ffc2

Browse files
committed
fix version reporting
1 parent 96836f0 commit 4a5ffc2

File tree

6 files changed

+21
-107
lines changed

6 files changed

+21
-107
lines changed

src/core/config/config.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import (
1616
"io/fs"
1717
"os"
1818
"path/filepath"
19-
"reflect"
20-
"sort"
2119
"strings"
2220
"sync"
2321
"time"
@@ -56,7 +54,7 @@ var (
5654

5755
func SetVersion(version, commit string) {
5856
ROOT_COMMAND.Version = version + "-" + commit
59-
Viper.SetDefault(VersionKey, version)
57+
Viper.Set(VersionKey, version)
6058
}
6159

6260
func Execute() error {
@@ -256,7 +254,6 @@ func UpdateAgentConfig(systemId string, updateTags []string, updateFeatures []st
256254
log.Errorf("Failed to register config: %v", err)
257255
return false, err
258256
}
259-
260257
// Update nil valued updateTags to empty slice for comparison
261258
if updateTags == nil {
262259
updateTags = []string{}
@@ -266,33 +263,12 @@ func UpdateAgentConfig(systemId string, updateTags []string, updateFeatures []st
266263
updateFeatures = []string{}
267264
}
268265

269-
// Sort tags and compare them
270-
sort.Strings(updateTags)
271-
sort.Strings(config.Tags)
272-
synchronizedTags := reflect.DeepEqual(updateTags, config.Tags)
273-
274266
Viper.Set(TagsKey, updateTags)
275267
config.Tags = Viper.GetStringSlice(TagsKey)
276268

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-
287269
Viper.Set(agent_config.FeaturesKey, updateFeatures)
288270
config.Features = Viper.GetStringSlice(agent_config.FeaturesKey)
289271

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-
296272
// Get the dynamic config path and use default dynamic config path if it's not
297273
// already set.
298274
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: false,
420+
updatedConf: true,
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, updated, tc.updatedConf)
461+
assert.Equal(t, tc.updatedConf, updated)
462462

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

src/plugins/config_reader.go

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

102102
synchronizeFeatures := false
103-
synchronizeTags := false
104103

105104
if payloadAgentConfig.Details.Features != nil {
106105
r.detailsMu.Lock()
@@ -128,20 +127,14 @@ func (r *ConfigReader) updateAgentConfig(payloadAgentConfig *proto.AgentConfig)
128127
r.detailsMu.Unlock()
129128
}
130129

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-
}
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")
145138
}
146139

147140
if payloadAgentConfig.Details.Extensions != nil {

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

Lines changed: 1 addition & 25 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: 1 addition & 25 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: 8 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)