in validator/validators/stress/stress_validator.go [416:467]
func (s *StressValidator) ValidateStressMetricWindows(metricName, metricNamespace string, metricDimensions []types.Dimension, metricSampleCount int, startTime, endTime time.Time) error {
var (
dataRate = fmt.Sprint(s.vConfig.GetDataRate())
boundAndPeriod = s.vConfig.GetAgentCollectionPeriod().Seconds()
receiver = s.vConfig.GetPluginsConfig()[0] //Assuming one plugin at a time
)
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.GetMetricStatistics(
metricName,
metricNamespace,
metricDimensions,
startTime,
endTime,
int32(boundAndPeriod),
[]types.Statistic{types.StatisticMaximum},
nil,
)
if err != nil {
return err
}
if len(metrics.Datapoints) == 0 || metrics.Datapoints[0].Maximum == nil {
return fmt.Errorf("\n getting metric %s failed with the namespace %s and dimension %v", metricName, metricNamespace, util.LogCloudWatchDimension(metricDimensions))
}
if _, ok := windowsMetricPluginBoundValue[dataRate][receiver]; !ok {
return fmt.Errorf("\n plugin %s does not have data rate", receiver)
}
if _, ok := windowsMetricPluginBoundValue[dataRate][receiver][metricName]; !ok {
return fmt.Errorf("\n metric %s does not have bound", metricName)
}
// Assuming each plugin are testing one at a time
// Validate if the corresponding metrics are within the acceptable range [acceptable value +- 30%]
metricValue := *metrics.Datapoints[0].Maximum
upperBoundValue := windowsMetricPluginBoundValue[dataRate][receiver][metricName] * (1 + metricErrorBound)
log.Printf("Metric %s within the namespace %s has value of %f and the upper bound is %f \n", metricName, metricNamespace, metricValue, upperBoundValue)
if metricValue < 0 || metricValue > upperBoundValue {
return fmt.Errorf("\n metric %s with value %f is larger than %f limit", metricName, metricValue, upperBoundValue)
}
// 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-5, metricSampleCount, int32(boundAndPeriod)); !ok {
return fmt.Errorf("\n metric %s is not within sample count bound [ %d, %d]", metricName, metricSampleCount-5, metricSampleCount)
}
return nil
}