generated from pagopa/pn-template-ms-be
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PN-10715: added CloudWatchMetricsPublisherWrapper
- Loading branch information
damiano.lozzi
committed
Apr 18, 2024
1 parent
58bcc05
commit 8011f87
Showing
3 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...java/it/pagopa/pn/ec/commons/model/pojo/cloudwatch/CloudWatchMetricsPublisherWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package it.pagopa.pn.ec.commons.model.pojo.cloudwatch; | ||
|
||
import lombok.CustomLog; | ||
import lombok.Getter; | ||
import lombok.experimental.FieldDefaults; | ||
import software.amazon.awssdk.metrics.MetricCollection; | ||
import software.amazon.awssdk.metrics.publishers.cloudwatch.CloudWatchMetricPublisher; | ||
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient; | ||
|
||
import java.time.Duration; | ||
|
||
|
||
@Getter | ||
@CustomLog | ||
@FieldDefaults(level = lombok.AccessLevel.PRIVATE, makeFinal = true) | ||
public class CloudWatchMetricsPublisherWrapper { | ||
|
||
CloudWatchMetricPublisher cloudWatchMetricPublisher; | ||
String namespace; | ||
int maximumCallsPerUpload; | ||
Duration uploadFrequency; | ||
CloudWatchAsyncClient cloudWatchClient; | ||
|
||
|
||
/** | ||
* Instantiates a new CloudWatchMetricsPublisherWrapper. | ||
* | ||
* @param nameSpace the name space | ||
* @param maximumCallsPerUpload the maximum calls per upload | ||
* @param uploadFrequency the upload frequency | ||
* @param cloudWatchClient the cloud watch client | ||
*/ | ||
public CloudWatchMetricsPublisherWrapper(String nameSpace, int maximumCallsPerUpload, Duration uploadFrequency, CloudWatchAsyncClient cloudWatchClient) { | ||
log.debug("Initializing CloudWatchMetricPublisher wrapper with args: nameSpace={}, maximumCallsPerUpload={}, uploadFrequencyMillis={}", nameSpace, maximumCallsPerUpload, uploadFrequency.toSeconds()+"s"); | ||
this.namespace = nameSpace; | ||
this.maximumCallsPerUpload = maximumCallsPerUpload; | ||
this.uploadFrequency = uploadFrequency; | ||
this.cloudWatchClient = cloudWatchClient; | ||
this.cloudWatchMetricPublisher = CloudWatchMetricPublisher.builder() | ||
.cloudWatchClient(cloudWatchClient) | ||
.namespace(nameSpace) | ||
.maximumCallsPerUpload(maximumCallsPerUpload) | ||
.uploadFrequency(uploadFrequency) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Method for calling the publish method of the CloudWatchMetricPublisher. | ||
* | ||
* @param metricCollection the metric collection to publish | ||
*/ | ||
public void publish(MetricCollection metricCollection) { | ||
log.debug("Publishing metric collection: {} ,namespace= {}", metricCollection, namespace); | ||
cloudWatchMetricPublisher.publish(metricCollection); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters