chore: do not return empty confId even if agentConf has not recommendations (#3773)

This commit is contained in:
Raj Kamal Singh 2023-10-19 14:35:45 +05:30 committed by GitHub
parent 6b2427f1c2
commit 838860da40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ package agentConf
import ( import (
"context" "context"
"crypto/sha256"
"fmt" "fmt"
"strings" "strings"
"sync" "sync"
@ -101,7 +102,7 @@ func (m *Manager) RecommendAgentConfig(currentConfYaml []byte) (
err error, err error,
) { ) {
recommendation := currentConfYaml recommendation := currentConfYaml
settingVersions := []string{} settingVersionsUsed := []string{}
for _, feature := range m.agentFeatures { for _, feature := range m.agentFeatures {
featureType := ElementTypeDef(feature.AgentFeatureType()) featureType := ElementTypeDef(feature.AgentFeatureType())
@ -124,7 +125,7 @@ func (m *Manager) RecommendAgentConfig(currentConfYaml []byte) (
} }
recommendation = updatedConf recommendation = updatedConf
configId := fmt.Sprintf("%s:%d", featureType, latestConfig.Version) configId := fmt.Sprintf("%s:%d", featureType, latestConfig.Version)
settingVersions = append(settingVersions, configId) settingVersionsUsed = append(settingVersionsUsed, configId)
m.updateDeployStatus( m.updateDeployStatus(
context.Background(), context.Background(),
@ -138,7 +139,16 @@ func (m *Manager) RecommendAgentConfig(currentConfYaml []byte) (
} }
configId = strings.Join(settingVersions, ",") if len(settingVersionsUsed) > 0 {
configId = strings.Join(settingVersionsUsed, ",")
} else {
// Do not return an empty configId even if no recommendations were made
hash := sha256.New()
hash.Write(recommendation)
configId = string(hash.Sum(nil))
}
return recommendation, configId, nil return recommendation, configId, nil
} }