log_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 #include <list>
17 #include <string>
18 
24 
26 
29 
31 
33 
37 
38 namespace Aws {
39 namespace CloudWatchLogs {
40 
41 // NOLINTNEXTLINE(google-default-arguments)
42 std::shared_ptr<LogService> LogServiceFactory::CreateLogService(
43  const std::string & log_group,
44  const std::string & log_stream,
45  const Aws::Client::ClientConfiguration & client_config,
46  const Aws::SDKOptions & sdk_options,
47  const CloudWatchOptions & cloudwatch_options)
48 {
49  Aws::InitAPI(sdk_options); // per the SDK team this only ever needs to be called once
50 
51  auto log_file_manager = std::make_shared<LogFileManager>(cloudwatch_options.file_manager_strategy_options);
52 
53  auto publisher = std::make_shared<LogPublisher>(log_group, log_stream, client_config);
54 
55  auto queue_monitor =
56  std::make_shared<Aws::DataFlow::QueueMonitor<Aws::FileManagement::TaskPtr<LogCollection>>>();
57 
59  cloudwatch_options.uploader_options.file_upload_batch_size,
60  cloudwatch_options.uploader_options.file_max_queue_size
61  };
62 
63  auto log_file_upload_streamer =
64  Aws::FileManagement::createFileUploadStreamer<LogCollection>(log_file_manager, file_upload_options);
65 
66  // connect publisher state changes to the File Streamer
67  publisher->addPublisherStateListener([upload_streamer = log_file_upload_streamer](const PublisherState& state) {
68  auto status =
69  (state == PublisherState::CONNECTED) ? Aws::DataFlow::Status::AVAILABLE : Aws::DataFlow::Status::UNAVAILABLE;
70  upload_streamer->onPublisherStateChange(status);
71  });
72 
73  // Create an observed queue to trigger a publish when data is available
74  auto file_data_queue =
75  std::make_shared<TaskObservedBlockingQueue<LogCollection>>(cloudwatch_options.uploader_options.file_max_queue_size);
76 
77  auto stream_data_queue = std::make_shared<TaskObservedBlockingQueue<LogCollection>>(cloudwatch_options.uploader_options.stream_max_queue_size);
78 
79  auto log_batcher = std::make_shared<LogBatcher>(
80  cloudwatch_options.uploader_options.batch_max_queue_size,
82  );
83  log_batcher->setLogFileManager(log_file_manager);
84 
85  log_file_upload_streamer->setSink(file_data_queue);
86  queue_monitor->addSource(file_data_queue, DataFlow::PriorityOptions{Aws::DataFlow::LOWEST_PRIORITY});
87 
88  log_batcher->setSink(stream_data_queue);
89  queue_monitor->addSource(stream_data_queue, DataFlow::PriorityOptions{Aws::DataFlow::HIGHEST_PRIORITY});
90 
91  auto log_service = std::make_shared<LogService>(publisher, log_batcher, log_file_upload_streamer);
92  log_service->setSource(queue_monitor);
93 
94  return log_service; // allow user to start
95 }
96 
97 } // namespace CloudWatchLogs
98 } // namespace Aws
Aws::DataFlow::UploaderOptions uploader_options
virtual std::shared_ptr< LogService > CreateLogService(const std::string &log_group, const std::string &log_stream, const Aws::Client::ClientConfiguration &client_config, const Aws::SDKOptions &sdk_options, const CloudWatchOptions &cloudwatch_options=kDefaultCloudWatchOptions)
Creates a new LogService object Factory method used to create a new LogService object, along with a creating and starting a LogPublisher for use with the LogService.
Aws::FileManagement::FileManagerStrategyOptions file_manager_strategy_options
Aws::DataFlow::ObservedBlockingQueue< TaskPtr< T >> TaskObservedBlockingQueue
PublisherState


cloudwatch_logs_common
Author(s): AWS RoboMaker
autogenerated on Fri May 7 2021 02:18:24