MCPcopy Create free account
hub / github.com/couchbase/cbft / massageStats

Function massageStats

ns_server.go:768–807  ·  view source on GitHub ↗
(buffer *bytes.Buffer, nsIndexStat map[string]interface{})

Source from the content-addressed store, hash-verified

766}
767
768func massageStats(buffer *bytes.Buffer, nsIndexStat map[string]interface{}) error {
769 statsBytes := buffer.Bytes()
770 pointers, err := jsonpointer.ListPointers(statsBytes)
771 if err != nil {
772 return err
773 }
774
775 countPointers := make([]string, 0)
776 for _, pointer := range pointers {
777 if strings.HasSuffix(pointer, "/count") ||
778 strings.HasSuffix(pointer, "/DocCount") ||
779 matchAnyFixedSuffixes(pointer) {
780 countPointers = append(countPointers, pointer)
781 }
782 }
783
784 countValueMap, err := jsonpointer.FindMany(statsBytes, countPointers)
785 if err != nil {
786 return err
787 }
788
789 for k, v := range countValueMap {
790 statName := convertStatName(k)
791 var statValue float64
792 err := json.Unmarshal(v, &statValue)
793 if err != nil {
794 return err
795 }
796 oldValue, ok := nsIndexStat[statName]
797 if ok {
798 switch oldValue := oldValue.(type) {
799 case float64:
800 oldValue += statValue
801 nsIndexStat[statName] = oldValue
802 }
803 }
804 }
805
806 return nil
807}
808
809var fixedSuffixToStatNameMapping = map[string]string{
810 "compacts": "total_compactions",

Callers 1

addFeedStatsFunction · 0.85

Calls 3

matchAnyFixedSuffixesFunction · 0.85
convertStatNameFunction · 0.85
UnmarshalMethod · 0.80

Tested by

no test coverage detected