22
33namespace AsyncAws \CloudWatch \Input ;
44
5+ use AsyncAws \CloudWatch \ValueObject \Entity ;
6+ use AsyncAws \CloudWatch \ValueObject \EntityMetricData ;
57use AsyncAws \CloudWatch \ValueObject \MetricDatum ;
68use AsyncAws \Core \Exception \InvalidArgument ;
79use AsyncAws \Core \Input ;
@@ -24,32 +26,80 @@ final class PutMetricDataInput extends Input
2426 private $ namespace ;
2527
2628 /**
27- * The data for the metric. The array can include no more than 1000 metrics per call.
29+ * The data for the metrics. Use this parameter if your metrics do not contain associated entities. The array can
30+ * include no more than 1000 metrics per call.
2831 *
29- * @required
32+ * The limit of metrics allowed, 1000, is the sum of both `EntityMetricData` and `MetricData` metrics.
3033 *
3134 * @var MetricDatum[]|null
3235 */
3336 private $ metricData ;
3437
38+ /**
39+ * Data for metrics that contain associated entity information. You can include up to two `EntityMetricData` objects,
40+ * each of which can contain a single `Entity` and associated metrics.
41+ *
42+ * The limit of metrics allowed, 1000, is the sum of both `EntityMetricData` and `MetricData` metrics.
43+ *
44+ * @var EntityMetricData[]|null
45+ */
46+ private $ entityMetricData ;
47+
48+ /**
49+ * Whether to accept valid metric data when an invalid entity is sent.
50+ *
51+ * - When set to `true`: Any validation error (for entity or metric data) will fail the entire request, and no data will
52+ * be ingested. The failed operation will return a 400 result with the error.
53+ * - When set to `false`: Validation errors in the entity will not associate the metric with the entity, but the metric
54+ * data will still be accepted and ingested. Validation errors in the metric data will fail the entire request, and no
55+ * data will be ingested.
56+ *
57+ * In the case of an invalid entity, the operation will return a `200` status, but an additional response header will
58+ * contain information about the validation errors. The new header, `X-Amzn-Failure-Message` is an enumeration of the
59+ * following values:
60+ *
61+ * - `InvalidEntity` - The provided entity is invalid.
62+ * - `InvalidKeyAttributes` - The provided `KeyAttributes` of an entity is invalid.
63+ * - `InvalidAttributes` - The provided `Attributes` of an entity is invalid.
64+ * - `InvalidTypeValue` - The provided `Type` in the `KeyAttributes` of an entity is invalid.
65+ * - `EntitySizeTooLarge` - The number of `EntityMetricData` objects allowed is 2.
66+ * - `MissingRequiredFields` - There are missing required fields in the `KeyAttributes` for the provided `Type`.
67+ *
68+ * For details of the requirements for specifying an entity, see How to add related information to telemetry [^1] in
69+ * the *CloudWatch User Guide*.
70+ *
71+ * This parameter is *required* when `EntityMetricData` is included.
72+ *
73+ * [^1]: https://docs.aws.amazon.com/adding-your-own-related-telemetry.html
74+ *
75+ * @var bool|null
76+ */
77+ private $ strictEntityValidation ;
78+
3579 /**
3680 * @param array{
3781 * Namespace?: string,
38- * MetricData?: array<MetricDatum|array>,
82+ * MetricData?: null|array<MetricDatum|array>,
83+ * EntityMetricData?: null|array<EntityMetricData|array>,
84+ * StrictEntityValidation?: null|bool,
3985 * '@region'?: string|null,
4086 * } $input
4187 */
4288 public function __construct (array $ input = [])
4389 {
4490 $ this ->namespace = $ input ['Namespace ' ] ?? null ;
4591 $ this ->metricData = isset ($ input ['MetricData ' ]) ? array_map ([MetricDatum::class, 'create ' ], $ input ['MetricData ' ]) : null ;
92+ $ this ->entityMetricData = isset ($ input ['EntityMetricData ' ]) ? array_map ([EntityMetricData::class, 'create ' ], $ input ['EntityMetricData ' ]) : null ;
93+ $ this ->strictEntityValidation = $ input ['StrictEntityValidation ' ] ?? null ;
4694 parent ::__construct ($ input );
4795 }
4896
4997 /**
5098 * @param array{
5199 * Namespace?: string,
52- * MetricData?: array<MetricDatum|array>,
100+ * MetricData?: null|array<MetricDatum|array>,
101+ * EntityMetricData?: null|array<EntityMetricData|array>,
102+ * StrictEntityValidation?: null|bool,
53103 * '@region'?: string|null,
54104 * }|PutMetricDataInput $input
55105 */
@@ -58,6 +108,14 @@ public static function create($input): self
58108 return $ input instanceof self ? $ input : new self ($ input );
59109 }
60110
111+ /**
112+ * @return EntityMetricData[]
113+ */
114+ public function getEntityMetricData (): array
115+ {
116+ return $ this ->entityMetricData ?? [];
117+ }
118+
61119 /**
62120 * @return MetricDatum[]
63121 */
@@ -71,6 +129,11 @@ public function getNamespace(): ?string
71129 return $ this ->namespace ;
72130 }
73131
132+ public function getStrictEntityValidation (): ?bool
133+ {
134+ return $ this ->strictEntityValidation ;
135+ }
136+
74137 /**
75138 * @internal
76139 */
@@ -92,6 +155,16 @@ public function request(): Request
92155 return new Request ('POST ' , $ uriString , $ query , $ headers , StreamFactory::create ($ body ));
93156 }
94157
158+ /**
159+ * @param EntityMetricData[] $value
160+ */
161+ public function setEntityMetricData (array $ value ): self
162+ {
163+ $ this ->entityMetricData = $ value ;
164+
165+ return $ this ;
166+ }
167+
95168 /**
96169 * @param MetricDatum[] $value
97170 */
@@ -109,24 +182,41 @@ public function setNamespace(?string $value): self
109182 return $ this ;
110183 }
111184
185+ public function setStrictEntityValidation (?bool $ value ): self
186+ {
187+ $ this ->strictEntityValidation = $ value ;
188+
189+ return $ this ;
190+ }
191+
112192 private function requestBody (): array
113193 {
114194 $ payload = [];
115195 if (null === $ v = $ this ->namespace ) {
116196 throw new InvalidArgument (\sprintf ('Missing parameter "Namespace" for "%s". The value cannot be null. ' , __CLASS__ ));
117197 }
118198 $ payload ['Namespace ' ] = $ v ;
119- if (null === $ v = $ this ->metricData ) {
120- throw new InvalidArgument (\sprintf ('Missing parameter "MetricData" for "%s". The value cannot be null. ' , __CLASS__ ));
199+ if (null !== $ v = $ this ->metricData ) {
200+ $ index = 0 ;
201+ foreach ($ v as $ mapValue ) {
202+ ++$ index ;
203+ foreach ($ mapValue ->requestBody () as $ bodyKey => $ bodyValue ) {
204+ $ payload ["MetricData.member. $ index. $ bodyKey " ] = $ bodyValue ;
205+ }
206+ }
121207 }
122-
123- $ index = 0 ;
124- foreach ($ v as $ mapValue ) {
125- ++$ index ;
126- foreach ($ mapValue ->requestBody () as $ bodyKey => $ bodyValue ) {
127- $ payload ["MetricData.member. $ index. $ bodyKey " ] = $ bodyValue ;
208+ if (null !== $ v = $ this ->entityMetricData ) {
209+ $ index = 0 ;
210+ foreach ($ v as $ mapValue ) {
211+ ++$ index ;
212+ foreach ($ mapValue ->requestBody () as $ bodyKey => $ bodyValue ) {
213+ $ payload ["EntityMetricData.member. $ index. $ bodyKey " ] = $ bodyValue ;
214+ }
128215 }
129216 }
217+ if (null !== $ v = $ this ->strictEntityValidation ) {
218+ $ payload ['StrictEntityValidation ' ] = $ v ? 'true ' : 'false ' ;
219+ }
130220
131221 return $ payload ;
132222 }
0 commit comments