Skip to content

Commit

Permalink
Allow for float metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
musa-asad committed Dec 15, 2024
1 parent 67f3247 commit 497c79b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/e2e/jmx/jmx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
36 changes: 36 additions & 0 deletions util/awsservice/cloudwatchmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 497c79b

Please sign in to comment.