aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/encode/format.h
blob: d363945ec3d86a73d4876fa5c09507ec17a4474b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#pragma once

#include <util/generic/strbuf.h>

namespace NMonitoring {
    namespace NFormatContenType {
        constexpr TStringBuf TEXT = "application/x-solomon-txt";
        constexpr TStringBuf JSON = "application/json";
        constexpr TStringBuf PROTOBUF = "application/x-solomon-pb";
        constexpr TStringBuf SPACK = "application/x-solomon-spack";
        constexpr TStringBuf PROMETHEUS = "text/plain";
        constexpr TStringBuf UNISTAT = "text/json";
    }

    namespace NFormatContentEncoding {
        constexpr TStringBuf IDENTITY = "identity";
        constexpr TStringBuf ZLIB = "zlib";
        constexpr TStringBuf LZ4 = "lz4";
        constexpr TStringBuf ZSTD = "zstd";
    }

    /**
     * Defines format types for metric encoders.
     */
    enum class EFormat {
        /**
         * Special case when it was not possible to determine format.
         */
        UNKNOWN,

        /**
         * Read more https://wiki.yandex-team.ru/solomon/api/dataformat/spackv1
         */
        SPACK,

        /**
         * Read more https://wiki.yandex-team.ru/solomon/api/dataformat/json
         */
        JSON,

        /**
         * Read more https://wiki.yandex-team.ru/golovan/userdocs/stat-handle
         */
        UNISTAT,

        /**
         * Simple protobuf format, only for testing purposes.
         */
        PROTOBUF,

        /**
         * Simple text representation, only for debug purposes.
         */
        TEXT,

        /**
         * Prometheus text-based format
         */
        PROMETHEUS,
    };

    /**
     * Defines compression algorithms for metric encoders.
     */
    enum class ECompression {
        /**
         * Special case when it was not possible to determine compression.
         */
        UNKNOWN,

        /**
         * Means no compression.
         */
        IDENTITY,

        /**
         * Using the zlib structure (defined in RFC 1950), with the
         * deflate compression algorithm and Adler32 checkums.
         */
        ZLIB,

        /**
         * Using LZ4 compression algorithm (read http://lz4.org for more info)
         * with XxHash32 checksums.
         */
        LZ4,

        /**
         * Using Zstandard compression algorithm (read http://zstd.net for more
         * info) with XxHash32 checksums.
         */
        ZSTD,
    };

    enum class EMetricsMergingMode {
        /**
         * Do not merge metric batches. If several points of the same metric were
         * added multiple times accross different writes, paste them as
         * separate metrics.
         *
         * Example:
         * COUNTER [(ts1, val1)] |     COUNTER [(ts1, val1)]
         * COUNTER [(ts2, val2)] | --> COUNTER [(ts2, val2)]
         * COUNTER [(ts3, val3)] |     COUNTER [(ts3, val3)]
         */
        DEFAULT,

        /**
         * If several points of the same metric were added multiple times across
         * different writes, merge all values to one timeseries.
         *
         * Example:
         * COUNTER [(ts1, val1)] |
         * COUNTER [(ts2, val2)] | --> COUNTER [(ts1, val1), (ts2, val2), (ts3, val3)]
         * COUNTER [(ts3, val3)] |
         */
        MERGE_METRICS,
    };

    /**
     * Matches serialization format by the given "Accept" header value.
     *
     * @param value  value of the "Accept" header.
     * @return most preffered serialization format type
     */
    EFormat FormatFromAcceptHeader(TStringBuf value);

    /**
     * Matches serialization format by the given "Content-Type" header value
     *
     * @param value value of the "Content-Type" header
     * @return message format
     */
    EFormat FormatFromContentType(TStringBuf value);

    /**
     * Returns value for "Content-Type" header determined by the given
     * format type.
     *
     * @param format  serialization format type
     * @return mime-type indentificator
     *         or empty string if format is UNKNOWN
     */
    TStringBuf ContentTypeByFormat(EFormat format);

    /**
     * Matches compression algorithm by the given "Accept-Encoding" header value.
     *
     * @param value  value of the "Accept-Encoding" header.
     * @return most preffered compression algorithm
     */
    ECompression CompressionFromAcceptEncodingHeader(TStringBuf value);

    /**
     * Matches compression algorithm by the given "Content-Encoding" header value.
     *
     * @param value  value of the "Accept-Encoding" header.
     * @return most preffered compression algorithm
     */
    ECompression CompressionFromContentEncodingHeader(TStringBuf value);

    /**
     * Returns value for "Content-Encoding" header determined by the given
     * compression algorithm.
     *
     * @param compression  encoding compression alg
     * @return media-type compresion algorithm
     *         or empty string if compression is UNKNOWN
     */
    TStringBuf ContentEncodingByCompression(ECompression compression);

}