From 6f3627620769d1cdc9172a298f6d0044fee6143e Mon Sep 17 00:00:00 2001 From: hardikl Date: Tue, 26 Sep 2023 19:15:44 +0530 Subject: [PATCH] feat: handle sorting in config side --- cmd/collectors/rest/rest.go | 1 + cmd/collectors/zapi/collector/zapi.go | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/collectors/rest/rest.go b/cmd/collectors/rest/rest.go index 9e43cab72..3dc51a0a2 100644 --- a/cmd/collectors/rest/rest.go +++ b/cmd/collectors/rest/rest.go @@ -502,6 +502,7 @@ func (r *Rest) HandleResults(result []gjson.Result, prop *prop, isEndPoint bool) labelString := r.String() labelArray = append(labelArray, labelString) } + sort.Strings(labelArray) instance.SetLabel(display, strings.Join(labelArray, ",")) } else { instance.SetLabel(display, value.String()) diff --git a/cmd/collectors/zapi/collector/zapi.go b/cmd/collectors/zapi/collector/zapi.go index 33078a9e2..22ce1681c 100644 --- a/cmd/collectors/zapi/collector/zapi.go +++ b/cmd/collectors/zapi/collector/zapi.go @@ -284,7 +284,9 @@ func (z *Zapi) PollData() (map[string]*matrix.Matrix, error) { // Handling array with comma separated values previousValue := instance.GetLabel(label) if isAppend && previousValue != "" { - instance.SetLabel(label, previousValue+","+value) + currentVal := strings.Split(previousValue+","+value, ",") + sort.Strings(currentVal) + instance.SetLabel(label, strings.Join(currentVal, ",")) z.Logger.Trace().Msgf(" > %slabel (%s) [%s] set value (%s)%s", color.Yellow, key, label, instance.GetLabel(label)+","+value, color.End) } else { instance.SetLabel(label, value)