format.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. namespace NMonitoring {
  4. namespace NFormatContenType {
  5. constexpr TStringBuf TEXT = "application/x-solomon-txt";
  6. constexpr TStringBuf JSON = "application/json";
  7. constexpr TStringBuf PROTOBUF = "application/x-solomon-pb";
  8. constexpr TStringBuf SPACK = "application/x-solomon-spack";
  9. constexpr TStringBuf PROMETHEUS = "text/plain";
  10. }
  11. namespace NFormatContentEncoding {
  12. constexpr TStringBuf IDENTITY = "identity";
  13. constexpr TStringBuf ZLIB = "zlib";
  14. constexpr TStringBuf LZ4 = "lz4";
  15. constexpr TStringBuf ZSTD = "zstd";
  16. }
  17. /**
  18. * Defines format types for metric encoders.
  19. */
  20. enum class EFormat {
  21. /**
  22. * Special case when it was not possible to determine format.
  23. */
  24. UNKNOWN,
  25. /**
  26. * Read more https://wiki.yandex-team.ru/solomon/api/dataformat/spackv1
  27. */
  28. SPACK,
  29. /**
  30. * Read more https://wiki.yandex-team.ru/solomon/api/dataformat/json
  31. */
  32. JSON,
  33. /**
  34. * Simple protobuf format, only for testing purposes.
  35. */
  36. PROTOBUF,
  37. /**
  38. * Simple text representation, only for debug purposes.
  39. */
  40. TEXT,
  41. /**
  42. * Prometheus text-based format
  43. */
  44. PROMETHEUS,
  45. };
  46. /**
  47. * Defines compression algorithms for metric encoders.
  48. */
  49. enum class ECompression {
  50. /**
  51. * Special case when it was not possible to determine compression.
  52. */
  53. UNKNOWN,
  54. /**
  55. * Means no compression.
  56. */
  57. IDENTITY,
  58. /**
  59. * Using the zlib structure (defined in RFC 1950), with the
  60. * deflate compression algorithm and Adler32 checkums.
  61. */
  62. ZLIB,
  63. /**
  64. * Using LZ4 compression algorithm (read http://lz4.org for more info)
  65. * with XxHash32 checksums.
  66. */
  67. LZ4,
  68. /**
  69. * Using Zstandard compression algorithm (read http://zstd.net for more
  70. * info) with XxHash32 checksums.
  71. */
  72. ZSTD,
  73. };
  74. enum class EMetricsMergingMode {
  75. /**
  76. * Do not merge metric batches. If several points of the same metric were
  77. * added multiple times accross different writes, paste them as
  78. * separate metrics.
  79. *
  80. * Example:
  81. * COUNTER [(ts1, val1)] | COUNTER [(ts1, val1)]
  82. * COUNTER [(ts2, val2)] | --> COUNTER [(ts2, val2)]
  83. * COUNTER [(ts3, val3)] | COUNTER [(ts3, val3)]
  84. */
  85. DEFAULT,
  86. /**
  87. * If several points of the same metric were added multiple times across
  88. * different writes, merge all values to one timeseries.
  89. *
  90. * Example:
  91. * COUNTER [(ts1, val1)] |
  92. * COUNTER [(ts2, val2)] | --> COUNTER [(ts1, val1), (ts2, val2), (ts3, val3)]
  93. * COUNTER [(ts3, val3)] |
  94. */
  95. MERGE_METRICS,
  96. };
  97. /**
  98. * Matches serialization format by the given "Accept" header value.
  99. *
  100. * @param value value of the "Accept" header.
  101. * @return most preffered serialization format type
  102. */
  103. EFormat FormatFromAcceptHeader(TStringBuf value);
  104. /**
  105. * Matches serialization format by the given "Content-Type" header value
  106. *
  107. * @param value value of the "Content-Type" header
  108. * @return message format
  109. */
  110. EFormat FormatFromContentType(TStringBuf value);
  111. /**
  112. * Returns value for "Content-Type" header determined by the given
  113. * format type.
  114. *
  115. * @param format serialization format type
  116. * @return mime-type indentificator
  117. * or empty string if format is UNKNOWN
  118. */
  119. TStringBuf ContentTypeByFormat(EFormat format);
  120. /**
  121. * Matches compression algorithm by the given "Accept-Encoding" header value.
  122. *
  123. * @param value value of the "Accept-Encoding" header.
  124. * @return most preffered compression algorithm
  125. */
  126. ECompression CompressionFromAcceptEncodingHeader(TStringBuf value);
  127. /**
  128. * Matches compression algorithm by the given "Content-Encoding" header value.
  129. *
  130. * @param value value of the "Accept-Encoding" header.
  131. * @return most preffered compression algorithm
  132. */
  133. ECompression CompressionFromContentEncodingHeader(TStringBuf value);
  134. /**
  135. * Returns value for "Content-Encoding" header determined by the given
  136. * compression algorithm.
  137. *
  138. * @param compression encoding compression alg
  139. * @return media-type compresion algorithm
  140. * or empty string if compression is UNKNOWN
  141. */
  142. TStringBuf ContentEncodingByCompression(ECompression compression);
  143. }