Skip to content

Commit

Permalink
Filter out metricCount=0 and its corresponding metricValue for servic…
Browse files Browse the repository at this point in the history
…e connect metric TargetResponseTime
  • Loading branch information
EC2 Default User authored and ubhattacharjya committed Jan 21, 2023
1 parent c52c644 commit 17daadd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
29 changes: 23 additions & 6 deletions agent/stats/service_connect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,17 @@ func convertToTACSStats(mf map[string]*prometheus.MetricFamily, taskId string) (
}
metricCounts = append(metricCounts, &metricCount)
}
metricCounts = convertHistogramMetricCounts(metricCounts)

metricValues, metricCounts = convertHistogramMetricCounts(metricValues, metricCounts)

// If all values are 0 in metricCount, then no need to send the metrics to TACS
if len(metricCounts) == 0 {
logger.Debug("There were no non-zero metricCount received for TargetResponseTime metric. Skipping this metric.", logger.Fields{
field.TaskID: taskId,
})
continue
}

default:
logger.Warn("Service connect stats received invalid Metric type", logger.Fields{
field.TaskID: taskId,
Expand Down Expand Up @@ -212,13 +222,20 @@ func (sc *ServiceConnectStats) resetStats() {
}

// CloudWatch accepts the histogram buckets in a disjoint manner while the prometheus emits these values in a cumulative way.
// This method performs that conversion
func convertHistogramMetricCounts(metricCounts []*int64) []*int64 {
prevCount := *metricCounts[0]
for i := 1; i < len(metricCounts); i++ {
// This method performs that conversion. We discard any metricCount that is 0 and also its corresponding metricValue.
func convertHistogramMetricCounts(metricValues []*float64, metricCounts []*int64) ([]*float64, []*int64) {
var mV []*float64
var mC []*int64
prevCount := int64(0)
for i := 0; i < len(metricCounts); i++ {
prevCount, *metricCounts[i] = *metricCounts[i], *metricCounts[i]-prevCount
if metricCounts[i] != nil && *metricCounts[i] != 0 {
mV = append(mV, metricValues[i])
mC = append(mC, metricCounts[i])
}
}
return metricCounts

return mV, mC
}

// This method sorts the dimensions according to the keyName.
Expand Down
14 changes: 11 additions & 3 deletions agent/stats/service_connect_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestRetrieveServiceConnectMetrics(t *testing.T) {
{
stats: `# TYPE MetricFamily3 histogram
MetricFamily3{DimensionX="value1", DimensionY="value2", Direction="egress", le="0.5"} 1
MetricFamily3{DimensionX="value1", DimensionY="value2", Direction="egress", le="1"} 2
MetricFamily3{DimensionX="value1", DimensionY="value2", Direction="egress", le="1"} 1
MetricFamily3{DimensionX="value1", DimensionY="value2", Direction="egress", le="5"} 3
`,
expectedStats: []*ecstcs.GeneralMetricsWrapper{
Expand All @@ -110,14 +110,22 @@ func TestRetrieveServiceConnectMetrics(t *testing.T) {
}},
GeneralMetrics: []*ecstcs.GeneralMetric{
{
MetricCounts: []*int64{aws.Int64(1), aws.Int64(1), aws.Int64(1)},
MetricCounts: []*int64{aws.Int64(1), aws.Int64(2)},
MetricName: aws.String("MetricFamily3"),
MetricValues: []*float64{aws.Float64(0.5), aws.Float64(1), aws.Float64(5)},
MetricValues: []*float64{aws.Float64(0.5), aws.Float64(5)},
},
},
},
},
},
{
stats: `# TYPE MetricFamily3 histogram
MetricFamily3{DimensionX="value1", DimensionY="value2", Direction="egress", le="0.5"} 0
MetricFamily3{DimensionX="value1", DimensionY="value2", Direction="egress", le="1"} 0
MetricFamily3{DimensionX="value1", DimensionY="value2", Direction="egress", le="5"} 0
`,
expectedStats: []*ecstcs.GeneralMetricsWrapper{},
},
}

for _, test := range tests {
Expand Down

0 comments on commit 17daadd

Please sign in to comment.