format.h 4.8 KB

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