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
|
#pragma once
#include <library/cpp/monlib/encode/encoder.h>
#include <library/cpp/monlib/encode/format.h>
#include <library/cpp/monlib/metrics/metric.h>
#include <util/generic/yexception.h>
//
// format specification available here:
// https://wiki.yandex-team.ru/solomon/api/dataformat/spackv1/
//
class IInputStream;
class IOutputStream;
namespace NMonitoring {
class TSpackDecodeError: public yexception {
};
constexpr auto EncodeMetricType(EMetricType mt) noexcept {
return static_cast<std::underlying_type_t<EMetricType>>(mt);
}
EMetricType DecodeMetricType(ui8 byte);
[[nodiscard]]
bool TryDecodeMetricType(ui8 byte, EMetricType* result);
///////////////////////////////////////////////////////////////////////////////
// EValueType
///////////////////////////////////////////////////////////////////////////////
enum class EValueType : ui8 {
NONE = 0x00,
ONE_WITHOUT_TS = 0x01,
ONE_WITH_TS = 0x02,
MANY_WITH_TS = 0x03,
};
constexpr auto EncodeValueType(EValueType vt) noexcept {
return static_cast<std::underlying_type_t<EValueType>>(vt);
}
EValueType DecodeValueType(ui8 byte);
[[nodiscard]]
bool TryDecodeValueType(ui8 byte, EValueType* result);
///////////////////////////////////////////////////////////////////////////////
// ETimePrecision
///////////////////////////////////////////////////////////////////////////////
enum class ETimePrecision : ui8 {
SECONDS = 0x00,
MILLIS = 0x01,
};
constexpr auto EncodeTimePrecision(ETimePrecision tp) noexcept {
return static_cast<std::underlying_type_t<ETimePrecision>>(tp);
}
ETimePrecision DecodeTimePrecision(ui8 byte);
[[nodiscard]]
bool TryDecodeTimePrecision(ui8 byte, ETimePrecision* result);
///////////////////////////////////////////////////////////////////////////////
// ECompression
///////////////////////////////////////////////////////////////////////////////
ui8 EncodeCompression(ECompression c) noexcept;
ECompression DecodeCompression(ui8 byte);
[[nodiscard]]
bool TryDecodeCompression(ui8 byte, ECompression* result);
///////////////////////////////////////////////////////////////////////////////
// TSpackHeader
///////////////////////////////////////////////////////////////////////////////
struct Y_PACKED TSpackHeader {
ui16 Magic = 0x5053; // "SP"
ui16 Version; // MSB - major version, LSB - minor version
ui16 HeaderSize = sizeof(TSpackHeader);
ui8 TimePrecision;
ui8 Compression;
ui32 LabelNamesSize;
ui32 LabelValuesSize;
ui32 MetricCount;
ui32 PointsCount;
// add new fields here
};
enum ESpackV1Version: ui16 {
SV1_00 = 0x0100,
SV1_01 = 0x0101,
SV1_02 = 0x0102
};
IMetricEncoderPtr EncoderSpackV1(
IOutputStream* out,
ETimePrecision timePrecision,
ECompression compression,
EMetricsMergingMode mergingMode = EMetricsMergingMode::DEFAULT
);
IMetricEncoderPtr EncoderSpackV12(
IOutputStream* out,
ETimePrecision timePrecision,
ECompression compression,
EMetricsMergingMode mergingMode = EMetricsMergingMode::DEFAULT,
TStringBuf metricNameLabel = "name"
);
void DecodeSpackV1(IInputStream* in, IMetricConsumer* c, TStringBuf metricNameLabel = "name");
}
|