@@ -6,7 +6,13 @@ package aws.sdk.kotlin.benchmarks.service.definitions
66
77import aws.sdk.kotlin.benchmarks.service.Common
88import aws.sdk.kotlin.services.cloudwatch.CloudWatchClient
9- import aws.sdk.kotlin.services.cloudwatch.model.*
9+ import aws.sdk.kotlin.services.cloudwatch.getMetricData
10+ import aws.sdk.kotlin.services.cloudwatch.listMetrics
11+ import aws.sdk.kotlin.services.cloudwatch.model.Dimension
12+ import aws.sdk.kotlin.services.cloudwatch.model.Metric
13+ import aws.sdk.kotlin.services.cloudwatch.model.MetricDataQuery
14+ import aws.sdk.kotlin.services.cloudwatch.model.MetricDatum
15+ import aws.sdk.kotlin.services.cloudwatch.putMetricData
1016import aws.smithy.kotlin.runtime.ExperimentalApi
1117import aws.smithy.kotlin.runtime.time.Instant
1218import java.util.*
@@ -18,6 +24,7 @@ class CloudwatchProtocolBenchmark : ServiceProtocolBenchmark<CloudWatchClient> {
1824 companion object {
1925 val suiteId = UUID .randomUUID()
2026 val baseTime = Instant .now() - 2 .hours
27+ const val TEST_NAME_SPACE = " SDK Benchmark Test Data"
2128 }
2229
2330 @OptIn(ExperimentalApi ::class )
@@ -42,71 +49,65 @@ class CloudwatchProtocolBenchmark : ServiceProtocolBenchmark<CloudWatchClient> {
4249 override val requireScaling = true
4350
4451 override suspend fun transact (client : CloudWatchClient , scale : Int , iteration : Int ) {
45- client.putMetricData(
46- PutMetricDataRequest {
47- namespace = " SDK Benchmark Test Data"
48- metricData = (0 until scale).map { metricDatumIndex ->
49- MetricDatum {
50- metricName = " TestMetric"
51- dimensions = listOf (
52- Dimension {
53- name = " TestDimension"
54- value = " $suiteId -$scale "
55- },
56- )
57- value = Random .nextDouble()
58- unit = null
59- timestamp = baseTime + ((metricDatumIndex + 1 ) * 2 ).seconds
60- }
61- }.toList()
62- },
63- )
52+ client.putMetricData {
53+ namespace = TEST_NAME_SPACE
54+ metricData = (0 until scale).map { metricDatumIndex ->
55+ MetricDatum {
56+ metricName = " TestMetric"
57+ dimensions = listOf (
58+ Dimension {
59+ name = " TestDimension"
60+ value = " $suiteId -$scale "
61+ },
62+ )
63+ value = Random .nextDouble()
64+ unit = null
65+ timestamp = baseTime + ((metricDatumIndex + 1 ) * 2 ).seconds
66+ }
67+ }.toList()
68+ }
6469 }
6570 }
6671
6772 private val getMetricDataBenchmark = object : AbstractOperationProtocolBenchmark <CloudWatchClient >(" Get metric data" ) {
6873 override val requireScaling = true
6974
7075 override suspend fun transact (client : CloudWatchClient , scale : Int , iteration : Int ) {
71- client.getMetricData(
72- GetMetricDataRequest {
73- startTime = baseTime
74- endTime = baseTime + 2 .hours
75- metricDataQueries = listOf (
76- MetricDataQuery {
77- id = " m0"
78- returnData = true
79- metricStat {
80- unit = null
81- stat = " Sum"
82- metric = Metric {
83- namespace = " TestNamespace"
84- metricName = " TestMetric"
85- dimensions = listOf (
86- Dimension {
87- name = " TestDimension"
88- value = " $suiteId -$scale "
89- },
90- )
91- }
92- period = 60
76+ client.getMetricData {
77+ startTime = baseTime
78+ endTime = baseTime + 2 .hours
79+ metricDataQueries = listOf (
80+ MetricDataQuery {
81+ id = " m0"
82+ returnData = true
83+ metricStat {
84+ unit = null
85+ stat = " Sum"
86+ metric = Metric {
87+ namespace = TEST_NAME_SPACE
88+ metricName = " TestMetric"
89+ dimensions = listOf (
90+ Dimension {
91+ name = " TestDimension"
92+ value = " $suiteId -$scale "
93+ },
94+ )
9395 }
94- },
95- )
96- },
97- )
96+ period = 60
97+ }
98+ },
99+ )
100+ }
98101 }
99102 }
100103
101104 private val listMetricsBenchmark = object : AbstractOperationProtocolBenchmark <CloudWatchClient >(" List metrics" ) {
102105 override val requireScaling = true
103106
104107 override suspend fun transact (client : CloudWatchClient , scale : Int , iteration : Int ) {
105- client.listMetrics(
106- ListMetricsRequest {
107- namespace = " TestNamespace"
108- },
109- )
108+ client.listMetrics {
109+ namespace = TEST_NAME_SPACE
110+ }
110111 }
111112 }
112113}
0 commit comments