diff --git a/internal/collector/recon/sharding.go b/internal/collector/recon/sharding.go index f7a0ebb..2f2b395 100644 --- a/internal/collector/recon/sharding.go +++ b/internal/collector/recon/sharding.go @@ -15,7 +15,6 @@ package recon import ( - "bytes" "encoding/json" "fmt" @@ -527,12 +526,6 @@ func (t *ShardingTask) UpdateMetrics() (map[string]int, error) { } for hostname, dataBytes := range outputPerHost { - if !json.Valid(dataBytes) { - //Replace instances of breaking null string errors with a 0. - //Workaround for unmarshalling, and consistent with eventual metric export value. (0: no error/1: error) - dataBytes = bytes.ReplaceAll(dataBytes, []byte(`"None"`), []byte(`0`)) - } - var data struct { ShardingStats ShardingStats `json:"sharding_stats"` } @@ -593,7 +586,7 @@ func (t *ShardingTask) UpdateMetrics() (map[string]int, error) { t.containerShardingInProgressActive.With(l).Set(float64(shardingProcess.Active)) t.containerShardingInProgressCleaved.With(l).Set(float64(shardingProcess.Cleaved)) t.containerShardingInProgressCreated.With(l).Set(float64(shardingProcess.Created)) - if shardingProcess.Error != `0` { + if shardingProcess.Error != "None" { t.containerShardingInProgressError.With(l).Set(float64(1)) } else { t.containerShardingInProgressError.With(l).Set(float64(0)) diff --git a/internal/collector/recon/utils.go b/internal/collector/recon/utils.go index 45a91a4..6b2464d 100644 --- a/internal/collector/recon/utils.go +++ b/internal/collector/recon/utils.go @@ -90,12 +90,15 @@ func splitOutputPerHost(output []byte, cmdArgs []string) (map[string][]byte, err logg.Debug("output from command 'swift-recon %s': %s: %s", util.CmdArgsToStr(cmdArgs), hostname, string(data)) - // sanitize JSON + // convert Python literals to JSON (best effort) data = bytes.ReplaceAll(data, []byte(`u'`), []byte(`'`)) data = bytes.ReplaceAll(data, []byte(`'`), []byte(`"`)) data = bytes.ReplaceAll(data, []byte(`True`), []byte(`true`)) data = bytes.ReplaceAll(data, []byte(`False`), []byte(`false`)) data = bytes.ReplaceAll(data, []byte(`None`), []byte(`"None"`)) + data = bytes.ReplaceAll(data, []byte(`""None""`), []byte(`"None"`)) + //^ We sometimes observe strings with the value "None". + //The None -> "None" replacement introduces double quoting there which we need to compensate for. //In the event that object store issues add escape characters to swift-recon output, strip these chracters to continue. data = []byte(stripEscapeChars(string(data)))