in validator/validators/basic/basic_validator.go [215:249]
func (s *BasicValidator) ValidateMetric(metricName, metricNamespace string, metricDimensions []cwtypes.Dimension, metricValue float64, metricSampleCount int, startTime, endTime time.Time) error {
var (
boundAndPeriod = s.vConfig.GetAgentCollectionPeriod().Seconds()
)
metricQueries := s.buildMetricQueries(metricName, metricNamespace, metricDimensions)
log.Printf("Start to collect and validate metric %s with the namespace %s, start time %v and end time %v \n", metricName, metricNamespace, startTime, endTime)
metrics, err := awsservice.GetMetricData(metricQueries, startTime, endTime)
if err != nil {
return err
}
if len(metrics.MetricDataResults) == 0 || len(metrics.MetricDataResults[0].Values) == 0 {
return fmt.Errorf("\n getting metric %s failed with the namespace %s and dimension %v", metricName, metricNamespace, util.LogCloudWatchDimension(metricDimensions))
}
// Validate if the metrics are not dropping any metrics and able to backfill within the same minute (e.g if the memory_rss metric is having collection_interval 1
// , it will need to have 60 sample counts - 1 datapoint / second)
if ok := awsservice.ValidateSampleCount(metricName, metricNamespace, metricDimensions, startTime, endTime, metricSampleCount, metricSampleCount, int32(boundAndPeriod)); !ok {
return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount, metricSampleCount)
}
// Validate if the corresponding metrics are within the acceptable range [acceptable value +- 10%]
actualMetricValue := metrics.MetricDataResults[0].Values[0]
upperBoundValue := metricValue * (1 + metricErrorBound)
lowerBoundValue := metricValue * (1 - metricErrorBound)
if metricValue != 0.0 && (actualMetricValue < lowerBoundValue || actualMetricValue > upperBoundValue) {
return fmt.Errorf("\n metric %s value %f is different from the actual value %f", metricName, metricValue, metrics.MetricDataResults[0].Values[0])
}
return nil
}