MCPcopy Index your code
hub / github.com/cortexproject/cortex / compareVector

Function compareVector

tools/querytee/response_comparator.go:131–174  ·  view source on GitHub ↗
(expectedRaw, actualRaw json.RawMessage, tolerance float64)

Source from the content-addressed store, hash-verified

129}
130
131func compareVector(expectedRaw, actualRaw json.RawMessage, tolerance float64) error {
132 var expected, actual model.Vector
133
134 err := json.Unmarshal(expectedRaw, &expected)
135 if err != nil {
136 return err
137 }
138
139 err = json.Unmarshal(actualRaw, &actual)
140 if err != nil {
141 return err
142 }
143
144 if len(expected) != len(actual) {
145 return fmt.Errorf("expected %d metrics but got %d", len(expected),
146 len(actual))
147 }
148
149 metricFingerprintToIndexMap := make(map[model.Fingerprint]int, len(expected))
150 for i, actualMetric := range actual {
151 metricFingerprintToIndexMap[actualMetric.Metric.Fingerprint()] = i
152 }
153
154 for _, expectedMetric := range expected {
155 actualMetricIndex, ok := metricFingerprintToIndexMap[expectedMetric.Metric.Fingerprint()]
156 if !ok {
157 return fmt.Errorf("expected metric %s missing from actual response", expectedMetric.Metric)
158 }
159
160 actualMetric := actual[actualMetricIndex]
161 err := compareSamplePair(model.SamplePair{
162 Timestamp: expectedMetric.Timestamp,
163 Value: expectedMetric.Value,
164 }, model.SamplePair{
165 Timestamp: actualMetric.Timestamp,
166 Value: actualMetric.Value,
167 }, tolerance)
168 if err != nil {
169 return errors.Wrapf(err, "sample pair not matching for metric %s", expectedMetric.Metric)
170 }
171 }
172
173 return nil
174}
175
176func compareScalar(expectedRaw, actualRaw json.RawMessage, tolerance float64) error {
177 var expected, actual model.Scalar

Callers 1

TestCompareVectorFunction · 0.85

Calls 2

compareSamplePairFunction · 0.85
UnmarshalMethod · 0.45

Tested by 1

TestCompareVectorFunction · 0.68