From 34a0b66bc2d48223748ed1cf5bc1b305c396bd74 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 26 Jan 2022 19:05:10 +0100 Subject: Adding upstream version 1.33.0. Signed-off-by: Daniel Baumann --- .../remote_write/remote_write_request.cc | 40 ++++++++++++++++++++++ .../prometheus/remote_write/remote_write_request.h | 6 ++++ 2 files changed, 46 insertions(+) (limited to 'exporting/prometheus') diff --git a/exporting/prometheus/remote_write/remote_write_request.cc b/exporting/prometheus/remote_write/remote_write_request.cc index 48d19efd6..cfd61271e 100644 --- a/exporting/prometheus/remote_write/remote_write_request.cc +++ b/exporting/prometheus/remote_write/remote_write_request.cc @@ -177,6 +177,46 @@ int pack_and_clear_write_request(void *write_request_p, char *buffer, size_t *si return 0; } +/** + * Writes an unpacked write request into a text buffer + * + * @param write_request_p the write request + * @param buffer a buffer, where text is written + * @param size the size of the buffer + * @return Returns 0 on success, 1 on failure + */ +int convert_write_request_to_string( + const char *compressed_write_request, + size_t compressed_size, + char *buffer, + size_t size) +{ + size_t uncompressed_size = 0; + + snappy::GetUncompressedLength(compressed_write_request, compressed_size, &uncompressed_size); + if (size < uncompressed_size) + return 1; + char *uncompressed_write_request = (char *)malloc(size); + + if (snappy::RawUncompress(compressed_write_request, compressed_size, uncompressed_write_request) == false) { + free(uncompressed_write_request); + return 1; + } + + WriteRequest *write_request = google::protobuf::Arena::CreateMessage(&arena); + if (write_request->ParseFromString(std::string(uncompressed_write_request, uncompressed_size)) == false) { + free(uncompressed_write_request); + return 1; + } + + std::string text_write_request(write_request->DebugString()); + text_write_request.copy(buffer, size); + + free(uncompressed_write_request); + + return 0; +} + /** * Shuts down the Protobuf library */ diff --git a/exporting/prometheus/remote_write/remote_write_request.h b/exporting/prometheus/remote_write/remote_write_request.h index e1dfacaf8..5f242b941 100644 --- a/exporting/prometheus/remote_write/remote_write_request.h +++ b/exporting/prometheus/remote_write/remote_write_request.h @@ -24,6 +24,12 @@ size_t get_write_request_size(void *write_request_p); int pack_and_clear_write_request(void *write_request_p, char *buffer, size_t *size); +int convert_write_request_to_string( + const char *compressed_write_request, + size_t compressed_size, + char *buffer, + size_t size); + void protocol_buffers_shutdown(); #ifdef __cplusplus -- cgit v1.2.3