ClientConfiguration.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/std/string/string.h>
  10. #include <AzCore/std/parallel/atomic.h>
  11. namespace AWSMetrics
  12. {
  13. constexpr char AwsMetricsLocalFileDir[] = "@user@/AWSMetrics/";
  14. constexpr char AwsMetricsLocalFileName[] = "metrics.json";
  15. //! ClientConfiguration is used to retrieve and store client settings from a local configuration JSON file.
  16. class ClientConfiguration
  17. {
  18. public:
  19. static constexpr const char AWSMetricsMaxQueueSizeInMbKey[] = "/Gems/AWSMetrics/MaxQueueSizeInMb";
  20. static constexpr const char AWSMetricsQueueFlushPeriodInSecondsKey[] = "/Gems/AWSMetrics/QueueFlushPeriodInSeconds";
  21. static constexpr const char AWSMetricsOfflineRecordingEnabledKey[] = "/Gems/AWSMetrics/OfflineRecording";
  22. static constexpr const char AWSMetricsMaxNumRetriesKey[] = "/Gems/AWSMetrics/MaxNumRetries";
  23. ClientConfiguration();
  24. //! Initialize the client settings based on the global setting registry.
  25. //! @return whether the operation is successful
  26. bool InitClientConfiguration();
  27. //! Retrieve the max queue size setting.
  28. //! @return Max queue size in bytes.
  29. AZ::s64 GetMaxQueueSizeInBytes() const;
  30. //! Retrieve the flush period setting.
  31. //! @return Flush period in seconds.
  32. AZ::s64 GetQueueFlushPeriodInSeconds() const;
  33. //! Status of the offline recording. Metrics will be sent to a local file instead of the backend if the offline recording is enabled.
  34. //! @return Whether the offline recording is enabled.
  35. bool OfflineRecordingEnabled() const;
  36. //! Retrieve the settings for the maximum number of retries.
  37. //! @return Maximum number of retries.
  38. AZ::s64 GetMaxNumRetries() const;
  39. //! Retrieve the directory of the local metrics file
  40. //! @return Directory of the local metrics file
  41. const char* GetMetricsFileDir() const;
  42. //! Retrieve the full path of the local metrics file
  43. //! @return Full path of the local metrics file
  44. const char* GetMetricsFileFullPath() const;
  45. //! Enable/Disable the offline recording.
  46. //! @param enable Whether to enable the offline recording.
  47. void UpdateOfflineRecordingStatus(bool enable);
  48. private:
  49. bool ResolveMetricsFilePath();
  50. double m_maxQueueSizeInMb; //< Default to 0.3MB on consideration of the Kinesis PutRecordBatch API limit (500 records/request).
  51. AZ::s64 m_queueFlushPeriodInSeconds; //< Default to 60 seconds to guarantee the near real time data input.
  52. AZStd::atomic_bool m_offlineRecordingEnabled; //< Default to false to disable the offline recording.
  53. AZ::s64 m_maxNumRetries; //< Maximum number of retries for submission.
  54. AZStd::string m_metricsDir;
  55. AZStd::string m_metricsFilePath;
  56. };
  57. }