diff --git a/test/e2e/jmx/jmx_test.go b/test/e2e/jmx/jmx_test.go index 9e1493371..c0b2ebd2c 100644 --- a/test/e2e/jmx/jmx_test.go +++ b/test/e2e/jmx/jmx_test.go @@ -260,13 +260,13 @@ func testTomcatSessions(t *testing.T) { startTime := time.Now().Add(-5 * time.Minute) endTime := time.Now() - hasActiveSessions := awsservice.ValidateSampleCount( + hasActiveSessions := awsservice.ValidateSampleCountFloat( "tomcat.sessions", "JVM_TOMCAT_E2E", nil, startTime, endTime, - 1, + 0.1, 1000, 60, ) diff --git a/util/awsservice/cloudwatchmetrics.go b/util/awsservice/cloudwatchmetrics.go index 59ef886b2..5a2d3d6dc 100644 --- a/util/awsservice/cloudwatchmetrics.go +++ b/util/awsservice/cloudwatchmetrics.go @@ -106,6 +106,42 @@ func ValidateSampleCount(metricName, namespace string, dimensions []types.Dimens return false } +func ValidateSampleCountFloat(metricName, namespace string, dimensions []types.Dimension, + startTime time.Time, endTime time.Time, + lowerBoundInclusive float64, upperBoundInclusive float64, periodInSeconds int32) bool { + + metricStatsInput := cloudwatch.GetMetricStatisticsInput{ + MetricName: aws.String(metricName), + Namespace: aws.String(namespace), + StartTime: aws.Time(startTime), + EndTime: aws.Time(endTime), + Period: aws.Int32(periodInSeconds), + Dimensions: dimensions, + Statistics: []types.Statistic{types.StatisticSampleCount}, + } + data, err := CwmClient.GetMetricStatistics(ctx, &metricStatsInput) + if err != nil { + return false + } + + var dataPoints float64 + log.Printf("These are the data points: %v", data) + log.Printf("These are the data points: %v", data.Datapoints) + + for _, datapoint := range data.Datapoints { + dataPoints += *datapoint.SampleCount + } + log.Printf("Number of datapoints for start time %v with endtime %v and period %d is %.3f is inclusive between %.3f and %.3f", + startTime, endTime, periodInSeconds, dataPoints, lowerBoundInclusive, upperBoundInclusive) + + if lowerBoundInclusive <= dataPoints && dataPoints <= upperBoundInclusive { + return true + } + + return false +} + + func GetMetricStatistics( metricName string, namespace string,