AWSMetricsServiceApi.h 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 <Framework/ServiceRequestJob.h>
  10. #include <MetricsQueue.h>
  11. namespace AWSMetrics
  12. {
  13. namespace ServiceAPI
  14. {
  15. //! Response for an individual metrics event from a PostMetricsEvents request.
  16. //! If the event is successfully sent to the backend, it receives an "Ok" result.
  17. //! If the event fails to be sent to the backend, the result includes an error code and an "Error" result.
  18. struct PostMetricsEventsResponseEntry
  19. {
  20. //! Identify the expected property type in the response entry for each individual metrics event and provide a location where the property value can be stored.
  21. //! @param key Name of the property.
  22. //! @param reader JSON reader to read the property.
  23. bool OnJsonKey(const char* key, AWSCore::JsonReader& reader);
  24. AZStd::string m_errorCode; //!< Error code if the individual metrics event failed to be sent.
  25. AZStd::string m_result; //!< Result for the processed individual metrics event. Expected value: "Error" or "Ok".
  26. };
  27. using PostMetricsEventsResponseEntries = AZStd::vector<PostMetricsEventsResponseEntry>;
  28. //! Response for all the processed metrics events from a PostMetricsEvents request.
  29. struct PostMetricsEventsResponse
  30. {
  31. //! Identify the expected property type in the response and provide a location where the property value can be stored.
  32. //! @param key Name of the property.
  33. //! @param reader JSON reader to read the property.
  34. bool OnJsonKey(const char* key, AWSCore::JsonReader& reader);
  35. int m_failedRecordCount{ 0 }; //!< Number of events that failed to be sent to the backend.
  36. PostMetricsEventsResponseEntries m_responseEntries; //! Response list for all the processed metrics events.
  37. int m_total{ 0 }; //!< Total number of events that were processed in the request.
  38. };
  39. //! Failure response for sending the PostMetricsEvents request.
  40. struct PostMetricsEventsError
  41. {
  42. //! Identify the expected property type in the failure response and provide a location where the property value can be stored.
  43. //! @param key Name of the property.
  44. //! @param reader JSON reader to read the property.
  45. bool OnJsonKey(const char* key, AWSCore::JsonReader& reader);
  46. //! Do not rename the following members since they are expected by the AWSCore dependency.
  47. AZStd::string message; //!< Error message.
  48. AZStd::string type; //!< Error type.
  49. };
  50. // Service RequestJobs
  51. AWS_FEATURE_GEM_SERVICE(AWSMetrics);
  52. //! POST request defined by api_spec.json to send metrics to the backend.
  53. //! The path for this service API is "/producer/events".
  54. class PostMetricsEventsRequest
  55. : public AWSCore::ServiceRequest
  56. {
  57. public:
  58. SERVICE_REQUEST(AWSMetrics, HttpMethod::HTTP_POST, "/producer/events");
  59. //! Request body for the service API request.
  60. struct Parameters
  61. {
  62. //! Build the service API request.
  63. //! @request Builder for generating the request.
  64. //! @return Whether the request is built successfully.
  65. bool BuildRequest(AWSCore::RequestBuilder& request);
  66. //! Write to the service API request body.
  67. //! @param writer JSON writer for the serialization.
  68. //! @return Whether the serialization is successful.
  69. bool WriteJson(AWSCore::JsonWriter& writer) const;
  70. MetricsQueue m_metricsQueue; //!< Metrics events to send via the service API request.
  71. };
  72. //! Do not rename the following members since they are expected by the AWSCore dependency.
  73. PostMetricsEventsResponse result; //! Success response.
  74. PostMetricsEventsError error; //! Failure response.
  75. Parameters parameters; //! Request parameter.
  76. };
  77. using PostMetricsEventsRequestJob = AWSCore::ServiceRequestJob<PostMetricsEventsRequest>;
  78. } // ServiceAPI
  79. } // AWSMetrics