diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/monlib/deprecated/json/writer.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/monlib/deprecated/json/writer.h')
-rw-r--r-- | library/cpp/monlib/deprecated/json/writer.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/library/cpp/monlib/deprecated/json/writer.h b/library/cpp/monlib/deprecated/json/writer.h new file mode 100644 index 0000000000..183288143c --- /dev/null +++ b/library/cpp/monlib/deprecated/json/writer.h @@ -0,0 +1,76 @@ +#pragma once + +#include <library/cpp/json/json_writer.h> + +namespace NMonitoring { + /** + * Deprecated writer of Solomon JSON format + * https://wiki.yandex-team.ru/solomon/api/dataformat/json + * + * This writer will be deleted soon, so please consider to use + * high level library library/cpp/monlib/encode which is decoupled from the + * particular format. + */ + class TDeprecatedJsonWriter { + private: + NJson::TJsonWriter JsonWriter; + enum EState { + STATE_ROOT, + STATE_DOCUMENT, + STATE_COMMON_LABELS, + STATE_METRICS, + STATE_METRIC, + STATE_LABELS, + }; + EState State; + + public: + explicit TDeprecatedJsonWriter(IOutputStream* out); + + void OpenDocument(); + void CloseDocument(); + + void OpenCommonLabels(); + void CloseCommonLabels(); + + void WriteCommonLabel(TStringBuf name, TStringBuf value); + + void OpenMetrics(); + void CloseMetrics(); + + void OpenMetric(); + void CloseMetric(); + + void OpenLabels(); + void CloseLabels(); + + void WriteLabel(TStringBuf name, TStringBuf value); + + template <typename... T> + void WriteLabels(T... pairs) { + OpenLabels(); + WriteLabelsInner(pairs...); + CloseLabels(); + } + + void WriteModeDeriv(); + + void WriteValue(long long value); + void WriteDoubleValue(double d); + + void WriteTs(ui64 ts); + + private: + void WriteLabelsInner(TStringBuf name, TStringBuf value) { + WriteLabel(name, value); + } + + template <typename... T> + void WriteLabelsInner(TStringBuf name, TStringBuf value, T... pairs) { + WriteLabel(name, value); + WriteLabelsInner(pairs...); + } + + inline void TransitionState(EState current, EState next); + }; +} |