metric_service_factory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 
22 
25 
29 
31 
35 
36 
37 namespace Aws {
38 namespace CloudWatchMetrics {
39 
40 // NOLINTNEXTLINE(google-default-arguments)
41 std::shared_ptr<MetricService> MetricServiceFactory::createMetricService(
42  const std::string & metrics_namespace,
43  const Aws::Client::ClientConfiguration & client_config,
44  const Aws::SDKOptions & sdk_options,
45  const CloudWatchOptions & cloudwatch_options)
46 {
47  Aws::InitAPI(sdk_options); // per the SDK team this only ever needs to be called once
48 
49  auto metric_file_manager = std::make_shared<MetricFileManager>(cloudwatch_options.file_manager_strategy_options);
50 
51  auto metric_publisher = std::make_shared<MetricPublisher>(metrics_namespace, client_config);
52 
53  auto queue_monitor =
54  std::make_shared<Aws::DataFlow::QueueMonitor<Aws::FileManagement::TaskPtr<MetricDatumCollection>>>();
55 
57  cloudwatch_options.uploader_options.file_upload_batch_size,
58  cloudwatch_options.uploader_options.file_max_queue_size
59  };
60 
61  auto metric_file_upload_streamer =
62  Aws::FileManagement::createFileUploadStreamer<MetricDatumCollection>(metric_file_manager, file_upload_options);
63 
64  // connect publisher state changes to the File Streamer
65  metric_publisher->addPublisherStateListener([upload_streamer = metric_file_upload_streamer](const PublisherState& state) {
66  auto status =
67  (state == PublisherState::CONNECTED) ? Aws::DataFlow::Status::AVAILABLE : Aws::DataFlow::Status::UNAVAILABLE;
68  upload_streamer->onPublisherStateChange(status);
69  });
70 
71  // Create an observed queue to trigger a publish when data is available
72  auto file_data_queue =
73  std::make_shared<TaskObservedBlockingQueue<MetricDatumCollection>>(cloudwatch_options.uploader_options.file_max_queue_size);
74 
75  auto stream_data_queue = std::make_shared<TaskObservedBlockingQueue<MetricDatumCollection>>(cloudwatch_options.uploader_options.stream_max_queue_size);
76 
77  metric_file_upload_streamer->setSink(file_data_queue);
78  queue_monitor->addSource(file_data_queue, DataFlow::PriorityOptions{Aws::DataFlow::LOWEST_PRIORITY});
79 
80  auto metric_batcher = std::make_shared<MetricBatcher>(
81  cloudwatch_options.uploader_options.batch_max_queue_size,
83  );
84  metric_batcher->setMetricFileManager(metric_file_manager);
85 
86  metric_batcher->setSink(stream_data_queue);
87  queue_monitor->addSource(stream_data_queue, Aws::DataFlow::PriorityOptions{Aws::DataFlow::HIGHEST_PRIORITY});
88 
89  auto metric_service = std::make_shared<MetricService>(metric_publisher, metric_batcher, metric_file_upload_streamer);
90  metric_service->setSource(queue_monitor);
91 
92  return metric_service;
93 }
94 
95 } // namespace CloudWatchMetrics
96 } // namespace Aws
Aws::FileManagement::FileManagerStrategyOptions file_manager_strategy_options
virtual std::shared_ptr< MetricService > createMetricService(const std::string &metrics_namespace, const Aws::Client::ClientConfiguration &client_config, const Aws::SDKOptions &sdk_options, const CloudWatchOptions &cloudwatch_options=kDefaultCloudWatchOptions)
Aws::DataFlow::ObservedBlockingQueue< TaskPtr< T >> TaskObservedBlockingQueue
PublisherState
Aws::DataFlow::UploaderOptions uploader_options
Class that handles sending metrics data to CloudWatch This class is responsible for emitting all the ...


cloudwatch_metrics_common
Author(s): AWS RoboMaker
autogenerated on Fri May 7 2021 02:18:25