diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:18 +0000 |
commit | 5da14042f70711ea5cf66e034699730335462f66 (patch) | |
tree | 0f6354ccac934ed87a2d555f45be4c831cf92f4a /src/fluent-bit/lib/ctraces/include | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz netdata-5da14042f70711ea5cf66e034699730335462f66.zip |
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/fluent-bit/lib/ctraces/include')
21 files changed, 1601 insertions, 0 deletions
diff --git a/src/fluent-bit/lib/ctraces/include/CMakeLists.txt b/src/fluent-bit/lib/ctraces/include/CMakeLists.txt new file mode 100644 index 000000000..139c1d546 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/CMakeLists.txt @@ -0,0 +1,5 @@ +file(GLOB ctracesHeaders "ctraces/*.h") +install(FILES ${ctracesHeaders} + DESTINATION ${CTR_INSTALL_INCLUDEDIR}/ctraces + COMPONENT headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ) diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_attributes.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_attributes.h new file mode 100644 index 000000000..1b14a4f40 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_attributes.h @@ -0,0 +1,44 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_ATTRIBUTES_H +#define CTR_ATTRIBUTES_H + +#include <ctraces/ctraces.h> + +#include <cfl/cfl.h> +#include <cfl/cfl_kvlist.h> + +struct ctrace_attributes { + struct cfl_kvlist *kv; +}; + +struct ctrace_attributes *ctr_attributes_create(); +void ctr_attributes_destroy(struct ctrace_attributes *attr); +int ctr_attributes_count(struct ctrace_attributes *attr); +int ctr_attributes_set_string(struct ctrace_attributes *attr, char *key, char *value); +int ctr_attributes_set_bool(struct ctrace_attributes *attr, char *key, int b); +int ctr_attributes_set_int64(struct ctrace_attributes *attr, char *key, int64_t value); +int ctr_attributes_set_double(struct ctrace_attributes *attr, char *key, double value); +int ctr_attributes_set_array(struct ctrace_attributes *attr, char *key, + struct cfl_array *value); +int ctr_attributes_set_kvlist(struct ctrace_attributes *attr, char *key, + struct cfl_kvlist *value); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_compat.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_compat.h new file mode 100644 index 000000000..02293e814 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_compat.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_COMPAT_H +#define CTR_COMPAT_H + +#ifdef _WIN32 + +#include <sys/types.h> +#include <sys/stat.h> +#include <windows.h> + +#ifndef ssize_t +typedef SSIZE_T ssize_t; +#endif + + +#else +#include <unistd.h> + +#endif /* !_WIN32 */ + +#endif /* !CTR_COMPAT_H */ diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_decode_msgpack.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_decode_msgpack.h new file mode 100644 index 000000000..e4689aadd --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_decode_msgpack.h @@ -0,0 +1,44 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 Eduardo Silva <eduardo@calyptia.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_DECODE_MSGPACK_H +#define CTR_DECODE_MSGPACK_H + +#include <ctraces/ctraces.h> + +#define CTR_DECODE_MSGPACK_SUCCESS (CTR_MPACK_SUCCESS) +#define CTR_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR (CTR_MPACK_INVALID_ARGUMENT_ERROR) +#define CTR_DECODE_MSGPACK_INVALID_STATE (CTR_MPACK_ERROR_CUTOFF + 1) +#define CTR_DECODE_MSGPACK_ALLOCATION_ERROR (CTR_MPACK_ERROR_CUTOFF + 2) +#define CTR_DECODE_MSGPACK_VARIANT_DECODE_ERROR (CTR_MPACK_ERROR_CUTOFF + 3) + +struct ctr_msgpack_decode_context { + struct ctrace_resource_span *resource_span; + struct ctrace_scope_span *scope_span; + struct ctrace_resource *resource; + struct ctrace *trace; + struct ctrace_span_event *event; + struct ctrace_span *span; + struct ctrace_link *link; +}; + +int ctr_decode_msgpack_create(struct ctrace **out_context, char *in_buf, size_t in_size, size_t *offset); +void ctr_decode_msgpack_destroy(struct ctrace *context); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_decode_opentelemetry.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_decode_opentelemetry.h new file mode 100644 index 000000000..c1ba2c301 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_decode_opentelemetry.h @@ -0,0 +1,42 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_DECODE_OPENTELEMETRY_H +#define CTR_DECODE_OPENTELEMETRY_H + +typedef enum { + CTR_OPENTELEMETRY_TYPE_ATTRIBUTE = 0, + CTR_OPENTELEMETRY_TYPE_ARRAY = 1, + CTR_OPENTELEMETRY_TYPE_KVLIST = 2, +} opentelemetry_decode_value_type; + +struct opentelemetry_decode_value { + opentelemetry_decode_value_type type; + union { + struct ctrace_attributes *ctr_attr; + struct cfl_array *cfl_arr; + struct cfl_kvlist *cfl_kvlist; + }; +}; + +int ctr_decode_opentelemetry_create(struct ctrace **out_ctr, char *in_buf, size_t in_size, + size_t *offset); +void ctr_decode_opentelemetry_destroy(struct ctrace *ctr); + +#endif
\ No newline at end of file diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_msgpack.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_msgpack.h new file mode 100644 index 000000000..1229a33f6 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_msgpack.h @@ -0,0 +1,28 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_ENCODE_MSGPACK_H +#define CTR_ENCODE_MSGPACK_H + +#include <ctraces/ctraces.h> + +int ctr_encode_msgpack_create(struct ctrace *ctx, char **out_buf, size_t *out_size); +void ctr_encode_msgpack_destroy(char *buf); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_opentelemetry.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_opentelemetry.h new file mode 100644 index 000000000..ed6093658 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_opentelemetry.h @@ -0,0 +1,28 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CMT_ENCODE_OPENTELEMETRY_H +#define CMT_ENCODE_OPENTELEMETRY_H + +#include <ctraces/ctraces.h> + +cfl_sds_t ctr_encode_opentelemetry_create(struct ctrace *ctr); +void ctr_encode_opentelemetry_destroy(cfl_sds_t text); + +#endif
\ No newline at end of file diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_text.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_text.h new file mode 100644 index 000000000..a9fa12d45 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_encode_text.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_ENCODE_TEXT_H +#define CTR_ENCODE_TEXT_H + +#include <ctraces/ctraces.h> + +cfl_sds_t ctr_encode_text_create(struct ctrace *ctx); +void ctr_encode_text_destroy(cfl_sds_t text); + + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_id.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_id.h new file mode 100644 index 000000000..91e27e9d3 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_id.h @@ -0,0 +1,44 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_ID_H +#define CTR_ID_H + +#define CTR_ID_DEFAULT_SIZE 16 +#define CTR_ID_OTEL_TRACE_SIZE 16 +#define CTR_ID_OTEL_SPAN_SIZE 8 + +#define CTR_ID_TRACE_DEFAULT "000000F1BI700000000000F1BI700000" +#define CTR_ID_SPAN_DEFAULT "000000F1BI700000" + +struct ctrace_id { + cfl_sds_t buf; +}; + +struct ctrace_id *ctr_id_create_random(size_t size); +struct ctrace_id *ctr_id_create(void *buf, size_t len); +void ctr_id_destroy(struct ctrace_id *cid); +int ctr_id_set(struct ctrace_id *cid, void *buf, size_t len); +int ctr_id_cmp(struct ctrace_id *cid1, struct ctrace_id *cid2); +size_t ctr_id_get_len(struct ctrace_id *cid); +void *ctr_id_get_buf(struct ctrace_id *cid); +cfl_sds_t ctr_id_to_lower_base16(struct ctrace_id *cid); +struct ctrace_id *ctr_id_from_base16(cfl_sds_t id); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_info.h.in b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_info.h.in new file mode 100644 index 000000000..98210fd14 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_info.h.in @@ -0,0 +1,28 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_INFO_H +#define CTR_INFO_H + +#define CTR_SOURCE_DIR "@CMAKE_SOURCE_DIR@" + +/* General flags set by /CMakeLists.txt */ +@CTR_BUILD_FLAGS@ + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_link.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_link.h new file mode 100644 index 000000000..6ff64741e --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_link.h @@ -0,0 +1,50 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_LINK_H +#define CTR_LINK_H + +#include <ctraces/ctraces.h> + +struct ctrace_link { + struct ctrace_id *trace_id; /* the unique traceID */ + struct ctrace_id *span_id; /* the unique span ID */ + cfl_sds_t trace_state; /* trace_state */ + struct ctrace_attributes *attr; /* attributes */ + uint32_t dropped_attr_count; /* number of attributes that were discarded */ + + /* --- INTERNAL --- */ + struct cfl_list _head; /* link to 'struct span->links' list */ +}; + +struct ctrace_link *ctr_link_create(struct ctrace_span *span, + void *trace_id_buf, size_t trace_id_len, + void *span_id_buf, size_t span_id_len); + +struct ctrace_link *ctr_link_create_with_cid(struct ctrace_span *span, + struct ctrace_id *trace_id_cid, + struct ctrace_id *span_id_cid); + +int ctr_link_set_trace_state(struct ctrace_link *link, char *trace_state); +int ctr_link_set_attributes(struct ctrace_link *link, struct ctrace_attributes *attr); +void ctr_link_set_dropped_attr_count(struct ctrace_link *link, uint32_t count); + +void ctr_link_destroy(struct ctrace_link *link); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_log.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_log.h new file mode 100644 index 000000000..c4aae2ad1 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_log.h @@ -0,0 +1,71 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_LOG_H +#define CTR_LOG_H + +#include <errno.h> + +/* Message types */ +#define CTR_LOG_OFF 0 +#define CTR_LOG_ERROR 1 +#define CTR_LOG_WARN 2 +#define CTR_LOG_INFO 3 /* default */ +#define CTR_LOG_DEBUG 4 +#define CTR_LOG_TRACE 5 + + +#define CTR_LOG_BUF_SIZE 256 + +void ctr_log_print(void *ctx, int level, const char *file, int line, + const char *fmt, ...); +int ctr_errno_print(int errnum, const char *file, int line); + +#define ctr_log_error(ctx, fmt, ...) \ + ctr_log_print(ctx, CTR_LOG_ERROR, __FILENAME__, \ + __LINE__, fmt, ##__VA_ARGS__) + +#define ctr_log_warn(ctx, fmt, ...) \ + ctr_log_print(ctx, CTR_LOG_WARN, __FILENAME__, \ + __LINE__, fmt, ##__VA_ARGS__) + +#define ctr_log_info(ctx, fmt, ...) \ + ctr_log_print(ctx, CTR_LOG_INFO, __FILENAME__, \ + __LINE__, fmt, ##__VA_ARGS__) + +#define ctr_log_debug(ctx, fmt, ...) \ + ctr_log_print(ctx, CTR_LOG_DEBUG, __FILENAME__, \ + __LINE__, fmt, ##__VA_ARGS__) + +#define ctr_log_trace(ctx, fmt, ...) \ + ctr_log_print(ctx, CTR_LOG_TRACE, __FILENAME__, \ + __LINE__, fmt, ##__VA_ARGS__) + +#ifdef __FILENAME__ +#define ctr_errno() ctr_errno_print(errno, __FILENAME__, __LINE__) +#else +#define ctr_errno() ctr_errno_print(errno, __FILE__, __LINE__) +#endif + +#ifdef _WIN32 +void ctr_winapi_error_print(const char *func, int line); +#define ctr_winapi_error() ctr_winapi_error_print(__func__, __LINE__) +#endif + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_mpack_utils.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_mpack_utils.h new file mode 100644 index 000000000..84f4aaa32 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_mpack_utils.h @@ -0,0 +1,56 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 Eduardo Silva <eduardo@calyptia.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_MPACK_UTILS_H +#define CTR_MPACK_UTILS_H + +#include <ctraces/ctr_mpack_utils_defs.h> +#include <cfl/cfl_sds.h> +#include <mpack/mpack.h> + +typedef int (*ctr_mpack_unpacker_entry_callback_fn_t)(mpack_reader_t *reader, + size_t index, void *context); + +struct ctr_mpack_map_entry_callback_t { + const char *identifier; + ctr_mpack_unpacker_entry_callback_fn_t handler; +}; + +int ctr_mpack_consume_nil_tag(mpack_reader_t *reader); +int ctr_mpack_consume_double_tag(mpack_reader_t *reader, double *output_buffer); +int ctr_mpack_consume_int_tag(mpack_reader_t *reader, int64_t *output_buffer); +int ctr_mpack_consume_int32_tag(mpack_reader_t *reader, int32_t *output_buffer); +int ctr_mpack_consume_int64_tag(mpack_reader_t *reader, int64_t *output_buffer); +int ctr_mpack_consume_uint_tag(mpack_reader_t *reader, uint64_t *output_buffer); +int ctr_mpack_consume_uint32_tag(mpack_reader_t *reader, uint32_t *output_buffer); +int ctr_mpack_consume_uint64_tag(mpack_reader_t *reader, uint64_t *output_buffer); +int ctr_mpack_consume_string_tag(mpack_reader_t *reader, cfl_sds_t *output_buffer); +int ctr_mpack_consume_binary_tag(mpack_reader_t *reader, cfl_sds_t *output_buffer); +int ctr_mpack_consume_string_or_nil_tag(mpack_reader_t *reader, cfl_sds_t *output_buffer); +int ctr_mpack_consume_binary_or_nil_tag(mpack_reader_t *reader, cfl_sds_t *output_buffer); +int ctr_mpack_unpack_map(mpack_reader_t *reader, + struct ctr_mpack_map_entry_callback_t *callback_list, + void *context); +int ctr_mpack_unpack_array(mpack_reader_t *reader, + ctr_mpack_unpacker_entry_callback_fn_t entry_processor_callback, + void *context); +int ctr_mpack_peek_array_length(mpack_reader_t *reader); +mpack_type_t ctr_mpack_peek_type(mpack_reader_t *reader); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_mpack_utils_defs.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_mpack_utils_defs.h new file mode 100644 index 000000000..239f0d8e2 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_mpack_utils_defs.h @@ -0,0 +1,40 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CMetrics + * ======== + * Copyright 2021 Eduardo Silva <eduardo@calyptia.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_MPACK_UTILS_DEFS_H +#define CTR_MPACK_UTILS_DEFS_H + +#define CTR_MPACK_SUCCESS 0 +#define CTR_MPACK_INSUFFICIENT_DATA 1 +#define CTR_MPACK_INVALID_ARGUMENT_ERROR 2 +#define CTR_MPACK_ALLOCATION_ERROR 3 +#define CTR_MPACK_CORRUPT_INPUT_DATA_ERROR 4 +#define CTR_MPACK_CONSUME_ERROR 5 +#define CTR_MPACK_ENGINE_ERROR 6 +#define CTR_MPACK_PENDING_MAP_ENTRIES 7 +#define CTR_MPACK_PENDING_ARRAY_ENTRIES 8 +#define CTR_MPACK_UNEXPECTED_KEY_ERROR 9 +#define CTR_MPACK_UNEXPECTED_DATA_TYPE_ERROR 10 +#define CTR_MPACK_ERROR_CUTOFF 20 + +#define CTR_MPACK_MAX_ARRAY_ENTRY_COUNT 65535 +#define CTR_MPACK_MAX_MAP_ENTRY_COUNT 512 +#define CTR_MPACK_MAX_STRING_LENGTH (1024 * 1000) + +#endif
\ No newline at end of file diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_random.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_random.h new file mode 100644 index 000000000..178a2f853 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_random.h @@ -0,0 +1,27 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_RANDOM_H +#define CTR_RANDOM_H + +#include <ctraces/ctraces.h> + +ssize_t ctr_random_get(void *buf, size_t len); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_resource.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_resource.h new file mode 100644 index 000000000..772931c1b --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_resource.h @@ -0,0 +1,50 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_RESOURCE_H +#define CTR_RESOURCE_H + +#include <ctraces/ctraces.h> + +struct ctrace_resource { + uint32_t dropped_attr_count; /* number of attributes that were discarded */ + struct ctrace_attributes *attr; /* attributes */ +}; + +struct ctrace_resource_span { + struct ctrace_resource *resource; + struct cfl_list scope_spans; + cfl_sds_t schema_url; + struct cfl_list _head; /* link to ctraces->resource_span list */ +}; + +/* resource */ +struct ctrace_resource *ctr_resource_create(); +struct ctrace_resource *ctr_resource_create_default(); +int ctr_resource_set_attributes(struct ctrace_resource *res, struct ctrace_attributes *attr); +void ctr_resource_set_dropped_attr_count(struct ctrace_resource *res, uint32_t count); +void ctr_resource_destroy(struct ctrace_resource *res); + +/* resource_span */ +struct ctrace_resource_span *ctr_resource_span_create(struct ctrace *ctx); +struct ctrace_resource *ctr_resource_span_get_resource(struct ctrace_resource_span *resource_span); +int ctr_resource_span_set_schema_url(struct ctrace_resource_span *resource_span, char *url); +void ctr_resource_span_destroy(struct ctrace_resource_span *resource_span); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_scope.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_scope.h new file mode 100644 index 000000000..98faca943 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_scope.h @@ -0,0 +1,53 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_SCOPE_SPAN_H +#define CTR_SCOPE_SPAN_H + +#include <ctraces/ctraces.h> +#include <ctraces/ctr_resource.h> + +struct ctrace_instrumentation_scope { + cfl_sds_t name; + cfl_sds_t version; + uint32_t dropped_attr_count; /* number of attributes that were discarded */ + struct ctrace_attributes *attr; /* attributes */ +}; + +struct ctrace_scope_span { + struct ctrace_instrumentation_scope *instrumentation_scope; + struct cfl_list spans; + cfl_sds_t schema_url; + struct cfl_list _head; /* link to ctrace_resource_span->scope_spans list */ +}; + +/* scope span */ +struct ctrace_scope_span *ctr_scope_span_create(struct ctrace_resource_span *resource_span); +void ctr_scope_span_destroy(struct ctrace_scope_span *scope_span); +int ctr_scope_span_set_schema_url(struct ctrace_scope_span *scope_span, char *url); +void ctr_scope_span_set_instrumentation_scope(struct ctrace_scope_span *scope_span, struct ctrace_instrumentation_scope *ins_scope); + +/* instrumentation scope */ +struct ctrace_instrumentation_scope *ctr_instrumentation_scope_create(char *name, char *version, + uint32_t dropped_attr_count, + struct ctrace_attributes *attr); +void ctr_instrumentation_scope_destroy(struct ctrace_instrumentation_scope *ins_scope); + +#endif + diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_span.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_span.h new file mode 100644 index 000000000..7947b6f73 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_span.h @@ -0,0 +1,157 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_SPAN_H +#define CTR_SPAN_H + +#include <ctraces/ctraces.h> +#include <ctraces/ctr_scope.h> + +/* + * OpenTelemetry Trace Protobuf defition + * ------------------------------------- + * https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/trace/v1/trace.proto + */ + +/* Span kind */ +#define CTRACE_SPAN_UNSPECIFIED 0 +#define CTRACE_SPAN_INTERNAL 1 +#define CTRACE_SPAN_SERVER 2 +#define CTRACE_SPAN_CLIENT 3 +#define CTRACE_SPAN_PRODUCER 4 +#define CTRACE_SPAN_CONSUMER 5 + +/* Status code */ +#define CTRACE_SPAN_STATUS_CODE_UNSET 0 +#define CTRACE_SPAN_STATUS_CODE_OK 1 +#define CTRACE_SPAN_STAUTS_CODE_ERROR 2 + +struct ctrace_span_status { + int code; + cfl_sds_t message; +}; + +struct ctrace_span_event { + uint64_t time_unix_nano; + + cfl_sds_t name; + + /* event attributes */ + struct ctrace_attributes *attr; + + /* number of attributes that were discarded */ + uint32_t dropped_attr_count; + + /* ---- INTERNAL --- */ + struct cfl_list _head; +}; + +/* Span */ +struct ctrace_span { + struct ctrace_id *trace_id; /* the unique span ID */ + struct ctrace_id *span_id; /* the unique span ID */ + struct ctrace_id *parent_span_id; /* any parent ? a NULL means a root span */ + cfl_sds_t trace_state; /* trace state */ + + cfl_sds_t name; /* user-name assigned */ + + int kind; /* span kind */ + uint64_t start_time_unix_nano; /* start time */ + uint64_t end_time_unix_nano; /* end time */ + + struct ctrace_attributes *attr; /* attributes */ + uint32_t dropped_attr_count; /* number of attributes that were discarded */ + + struct cfl_list events; /* events */ + uint32_t dropped_events_count; /* number of events that were discarded */ + + struct cfl_list links; /* links */ + uint32_t dropped_links_count; /* number of links that were discarded */ + + struct ctrace_span_status status; /* status code */ + + /* --- INTERNAL --- */ + + /* link to 'struct scope_span->spans' list */ + struct cfl_list _head; + + /* link to global list on 'struct ctrace->span_list' */ + struct cfl_list _head_global; + + + /* references from parent contexts */ + struct ctrace_scope_span *scope_span; + struct ctrace *ctx; /* parent ctrace context */ +}; + +struct ctrace_span *ctr_span_create(struct ctrace *ctx, struct ctrace_scope_span *scope_span, cfl_sds_t name, + struct ctrace_span *parent); + +void ctr_span_destroy(struct ctrace_span *span); + +int ctr_span_set_status(struct ctrace_span *span, int code, char *message); +void ctr_span_set_dropped_events_count(struct ctrace_span *span, uint32_t count); + +/* span IDs */ +int ctr_span_set_trace_id(struct ctrace_span *span, void *buf, size_t len); +int ctr_span_set_trace_id_with_cid(struct ctrace_span *span, struct ctrace_id *cid); +int ctr_span_set_span_id(struct ctrace_span *span, void *buf, size_t len); +int ctr_span_set_span_id_with_cid(struct ctrace_span *span, struct ctrace_id *cid); +int ctr_span_set_parent_span_id(struct ctrace_span *span, void *buf, size_t len); +int ctr_span_set_parent_span_id_with_cid(struct ctrace_span *span, struct ctrace_id *cid); + +/* attributes */ +int ctr_span_set_attribute_string(struct ctrace_span *span, char *key, char *value); +int ctr_span_set_attribute_bool(struct ctrace_span *span, char *key, int b); +int ctr_span_set_attribute_int64(struct ctrace_span *span, char *key, int64_t value); +int ctr_span_set_attribute_double(struct ctrace_span *span, char *key, double value); +int ctr_span_set_attribute_array(struct ctrace_span *span, char *key, + struct cfl_array *value); +int ctr_span_set_attribute_kvlist(struct ctrace_span *span, char *key, + struct cfl_kvlist *value); +void ctr_span_set_dropped_attributes_count(struct ctrace_span *span, uint32_t count); + + +/* time */ +void ctr_span_start(struct ctrace *ctx, struct ctrace_span *span); +void ctr_span_start_ts(struct ctrace *ctx, struct ctrace_span *span, uint64_t ts); + +void ctr_span_end(struct ctrace *ctx, struct ctrace_span *span); +void ctr_span_end_ts(struct ctrace *ctx, struct ctrace_span *span, uint64_t ts); + +/* kind */ +int ctr_span_kind_set(struct ctrace_span *span, int kind); +char *ctr_span_kind_string(struct ctrace_span *span); + +/* events */ +struct ctrace_span_event *ctr_span_event_add(struct ctrace_span *span, char *name); +struct ctrace_span_event *ctr_span_event_add_ts(struct ctrace_span *span, char *name, uint64_t ts); +void ctr_span_event_set_dropped_attributes_count(struct ctrace_span_event *event, uint32_t count); +void ctr_span_event_delete(struct ctrace_span_event *event); + +int ctr_span_event_set_attribute_string(struct ctrace_span_event *event, char *key, char *value); +int ctr_span_event_set_attribute_bool(struct ctrace_span_event *event, char *key, int b); +int ctr_span_event_set_attribute_int(struct ctrace_span_event *event, char *key, int value); +int ctr_span_event_set_attribute_double(struct ctrace_span_event *event, char *key, double value); +int ctr_span_event_set_attribute_array(struct ctrace_span_event *event, char *key, + struct cfl_array *value); +int ctr_span_event_set_attribute_kvlist(struct ctrace_span_event *event, char *key, + struct cfl_kvlist *value); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_variant_utils.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_variant_utils.h new file mode 100644 index 000000000..c338be1b0 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_variant_utils.h @@ -0,0 +1,627 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CMetrics + * ======== + * Copyright 2021 Eduardo Silva <eduardo@calyptia.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_VARIANT_UTILS_H +#define CTR_VARIANT_UTILS_H + +#include <mpack/mpack.h> + +/* These are the only functions meant for general use, + * the reason why the kvlist packing and unpacking + * functions are exposed is the internal and external + * metadata kvlists in the cmetrics context are not + * contained by a variant instance. + * + * Result : + * Upon success all of these return 0, otherwise they will + * raise the innermost error code which should be treated + * as an opaque value. + * + * Notes : + * When decoding -1 means the check after mpack_read_tag + * failed and -2 means the type was not the one expected + */ + +static inline int pack_cfl_variant(mpack_writer_t *writer, + struct cfl_variant *value); + +static inline int pack_cfl_variant_kvlist(mpack_writer_t *writer, + struct cfl_kvlist *kvlist); + +static inline int unpack_cfl_variant(mpack_reader_t *reader, + struct cfl_variant **value); + +static inline int unpack_cfl_kvlist(mpack_reader_t *reader, + struct cfl_kvlist **result_kvlist); + +/* Packers */ +static inline int pack_cfl_variant_string(mpack_writer_t *writer, + char *value) +{ + mpack_write_cstr(writer, value); + + return 0; +} + +static inline int pack_cfl_variant_binary(mpack_writer_t *writer, + char *value, + size_t length) +{ + mpack_write_bin(writer, value, length); + + return 0; +} + +static inline int pack_cfl_variant_boolean(mpack_writer_t *writer, + unsigned int value) +{ + mpack_write_bool(writer, value); + + return 0; +} + +static inline int pack_cfl_variant_int64(mpack_writer_t *writer, + int64_t value) +{ + mpack_write_int(writer, value); + + return 0; +} + +static inline int pack_cfl_variant_double(mpack_writer_t *writer, + double value) +{ + mpack_write_double(writer, value); + + return 0; +} + +static inline int pack_cfl_variant_array(mpack_writer_t *writer, + struct cfl_array *array) +{ + size_t entry_count; + struct cfl_variant *entry_value; + int result; + size_t index; + + entry_count = array->entry_count; + + mpack_start_array(writer, entry_count); + + for (index = 0 ; index < entry_count ; index++) { + entry_value = cfl_array_fetch_by_index(array, index); + + if (entry_value == NULL) { + return -1; + } + + result = pack_cfl_variant(writer, entry_value); + + if (result != 0) { + return result; + } + } + + mpack_finish_array(writer); + + return 0; +} + +static inline int pack_cfl_variant_kvlist(mpack_writer_t *writer, + struct cfl_kvlist *kvlist) { + size_t entry_count; + struct cfl_list *iterator; + struct cfl_kvpair *kvpair; + int result; + + entry_count = cfl_kvlist_count(kvlist); + + mpack_start_map(writer, entry_count); + + cfl_list_foreach(iterator, &kvlist->list) { + kvpair = cfl_list_entry(iterator, struct cfl_kvpair, _head); + + mpack_write_cstr(writer, kvpair->key); + + result = pack_cfl_variant(writer, kvpair->val); + + if (result != 0) { + return result; + } + } + + mpack_finish_map(writer); + + return 0; +} + +static inline int pack_cfl_variant(mpack_writer_t *writer, + struct cfl_variant *value) +{ + int result; + + if (value->type == CFL_VARIANT_STRING) { + result = pack_cfl_variant_string(writer, value->data.as_string); + } + else if (value->type == CFL_VARIANT_BOOL) { + result = pack_cfl_variant_boolean(writer, value->data.as_bool); + } + else if (value->type == CFL_VARIANT_INT) { + result = pack_cfl_variant_int64(writer, value->data.as_int64); + } + else if (value->type == CFL_VARIANT_DOUBLE) { + result = pack_cfl_variant_double(writer, value->data.as_double); + } + else if (value->type == CFL_VARIANT_ARRAY) { + result = pack_cfl_variant_array(writer, value->data.as_array); + } + else if (value->type == CFL_VARIANT_KVLIST) { + result = pack_cfl_variant_kvlist(writer, value->data.as_kvlist); + } + else if (value->type == CFL_VARIANT_BYTES) { + result = pack_cfl_variant_binary(writer, + value->data.as_bytes, + cfl_sds_len(value->data.as_bytes)); + } + else if (value->type == CFL_VARIANT_REFERENCE) { + result = pack_cfl_variant_string(writer, value->data.as_string); + } + else { + result = -1; + } + + return result; +} + +/* Unpackers */ + +static inline int unpack_cfl_variant_read_tag(mpack_reader_t *reader, + mpack_tag_t *tag, + mpack_type_t expected_type) +{ + *tag = mpack_read_tag(reader); + + if (mpack_ok != mpack_reader_error(reader)) { + return -1; + } + + if (mpack_tag_type(tag) != expected_type) { + return -2; + } + + return 0; +} + +static inline int unpack_cfl_array(mpack_reader_t *reader, + struct cfl_array **result_array) +{ + struct cfl_array *internal_array; + size_t entry_count; + struct cfl_variant *entry_value; + int result; + size_t index; + mpack_tag_t tag; + + result = unpack_cfl_variant_read_tag(reader, &tag, mpack_type_array); + + if (result != 0) { + return result; + } + + entry_count = mpack_tag_array_count(&tag); + + internal_array = cfl_array_create(entry_count); + + if (internal_array == NULL) { + return -3; + } + + for (index = 0 ; index < entry_count ; index++) { + result = unpack_cfl_variant(reader, &entry_value); + + if (result != 0) { + cfl_array_destroy(internal_array); + + return -4; + } + + result = cfl_array_append(internal_array, entry_value); + + if (result != 0) { + cfl_array_destroy(internal_array); + + return -5; + } + } + + mpack_done_array(reader); + + if (mpack_reader_error(reader) != mpack_ok) { + cfl_array_destroy(internal_array); + + return -6; + } + + *result_array = internal_array; + + return 0; +} + +static inline int unpack_cfl_kvlist(mpack_reader_t *reader, + struct cfl_kvlist **result_kvlist) +{ + struct cfl_kvlist *internal_kvlist; + char key_name[256]; + size_t entry_count; + size_t key_length; + struct cfl_variant *key_value; + mpack_tag_t key_tag; + int result; + size_t index; + mpack_tag_t tag; + + result = unpack_cfl_variant_read_tag(reader, &tag, mpack_type_map); + + if (result != 0) { + return result; + } + + entry_count = mpack_tag_map_count(&tag); + + internal_kvlist = cfl_kvlist_create(); + + if (internal_kvlist == NULL) { + return -3; + } + + result = 0; + key_value = NULL; + + for (index = 0 ; index < entry_count ; index++) { + result = unpack_cfl_variant_read_tag(reader, &key_tag, mpack_type_str); + + if (result != 0) { + result = -4; + + break; + } + + key_length = mpack_tag_str_length(&key_tag); + + if (key_length >= sizeof(key_name)) { + result = -5; + + break; + } + + mpack_read_cstr(reader, key_name, sizeof(key_name), key_length); + + key_name[key_length] = '\0'; + + mpack_done_str(reader); + + if (mpack_ok != mpack_reader_error(reader)) { + result = -6; + + break; + } + + result = unpack_cfl_variant(reader, &key_value); + + if (result != 0) { + printf("VARIANT UNPACK ERROR : [%s] = %d\n", key_name, result); + result = -7; + + break; + } + + result = cfl_kvlist_insert(internal_kvlist, key_name, key_value); + + if (result != 0) { + result = -8; + + break; + } + + key_value = NULL; + } + + mpack_done_map(reader); + + if (mpack_reader_error(reader) != mpack_ok) { + result = -9; + } + + if (result != 0) { + cfl_kvlist_destroy(internal_kvlist); + + if (key_value != NULL) { + cfl_variant_destroy(key_value); + } + } + else { + *result_kvlist = internal_kvlist; + } + + return result; +} + +static inline int unpack_cfl_variant_string(mpack_reader_t *reader, + struct cfl_variant **value) +{ + size_t value_length; + char *value_data; + int result; + mpack_tag_t tag; + + result = unpack_cfl_variant_read_tag(reader, &tag, mpack_type_str); + + if (result != 0) { + return result; + } + + value_length = mpack_tag_str_length(&tag); + + value_data = cfl_sds_create_size(value_length + 1); + + if (value_data == NULL) { + return -3; + } + + cfl_sds_set_len(value_data, value_length); + + mpack_read_cstr(reader, value_data, value_length + 1, value_length); + + mpack_done_str(reader); + + if (mpack_reader_error(reader) != mpack_ok) { + cfl_sds_destroy(value_data); + + return -4; + } + + *value = cfl_variant_create_from_reference(value_data); + + if (*value == NULL) { + return -5; + } + + (*value)->type = CFL_VARIANT_STRING; + + return 0; +} + +static inline int unpack_cfl_variant_binary(mpack_reader_t *reader, + struct cfl_variant **value) +{ + size_t value_length; + char *value_data; + int result; + mpack_tag_t tag; + + result = unpack_cfl_variant_read_tag(reader, &tag, mpack_type_bin); + + if (result != 0) { + return result; + } + + value_length = mpack_tag_bin_length(&tag); + + value_data = cfl_sds_create_size(value_length); + + if (value_data == NULL) { + return -3; + } + + cfl_sds_set_len(value_data, value_length); + + mpack_read_bytes(reader, value_data, value_length); + + mpack_done_bin(reader); + + if (mpack_reader_error(reader) != mpack_ok) { + cfl_sds_destroy(value_data); + + return -4; + } + + *value = cfl_variant_create_from_reference(value_data); + + if (*value == NULL) { + return -5; + } + + (*value)->type = CFL_VARIANT_BYTES; + + return 0; +} + +static inline int unpack_cfl_variant_boolean(mpack_reader_t *reader, + struct cfl_variant **value) +{ + int result; + mpack_tag_t tag; + + result = unpack_cfl_variant_read_tag(reader, &tag, mpack_type_bool); + + if (result != 0) { + return result; + } + + *value = cfl_variant_create_from_bool((unsigned int) mpack_tag_bool_value(&tag)); + + if (*value == NULL) { + return -3; + } + + return 0; +} + +static inline int unpack_cfl_variant_uint64(mpack_reader_t *reader, + struct cfl_variant **value) +{ + int result; + mpack_tag_t tag; + + result = unpack_cfl_variant_read_tag(reader, &tag, mpack_type_uint); + + if (result != 0) { + return result; + } + + *value = cfl_variant_create_from_int64((int64_t) mpack_tag_uint_value(&tag)); + + if (*value == NULL) { + return -3; + } + + return 0; +} + +static inline int unpack_cfl_variant_int64(mpack_reader_t *reader, + struct cfl_variant **value) +{ + int result; + mpack_tag_t tag; + + result = unpack_cfl_variant_read_tag(reader, &tag, mpack_type_int); + + if (result != 0) { + return result; + } + + *value = cfl_variant_create_from_int64((int64_t) mpack_tag_int_value(&tag)); + + if (*value == NULL) { + return -3; + } + + return 0; +} + +static inline int unpack_cfl_variant_double(mpack_reader_t *reader, + struct cfl_variant **value) +{ + int result; + mpack_tag_t tag; + + result = unpack_cfl_variant_read_tag(reader, &tag, mpack_type_double); + + if (result != 0) { + return result; + } + + *value = cfl_variant_create_from_double(mpack_tag_double_value(&tag)); + + if (*value == NULL) { + return -3; + } + + return 0; +} + +static inline int unpack_cfl_variant_array(mpack_reader_t *reader, + struct cfl_variant **value) +{ + struct cfl_array *unpacked_array; + int result; + + result = unpack_cfl_array(reader, &unpacked_array); + + if (result != 0) { + return result; + } + + *value = cfl_variant_create_from_array(unpacked_array); + + if (*value == NULL) { + return -3; + } + + return 0; +} + +static inline int unpack_cfl_variant_kvlist(mpack_reader_t *reader, + struct cfl_variant **value) +{ + struct cfl_kvlist *unpacked_kvlist; + int result; + + result = unpack_cfl_kvlist(reader, &unpacked_kvlist); + + if (result != 0) { + return result; + } + + *value = cfl_variant_create_from_kvlist(unpacked_kvlist); + + if (*value == NULL) { + return -3; + } + + return 0; +} + +static inline int unpack_cfl_variant(mpack_reader_t *reader, + struct cfl_variant **value) +{ + mpack_type_t value_type; + int result; + mpack_tag_t tag; + + tag = mpack_peek_tag(reader); + + if (mpack_ok != mpack_reader_error(reader)) { + return -1; + } + + value_type = mpack_tag_type(&tag); + + if (value_type == mpack_type_str) { + result = unpack_cfl_variant_string(reader, value); + } + else if (value_type == mpack_type_bool) { + result = unpack_cfl_variant_boolean(reader, value); + } + else if (value_type == mpack_type_int) { + result = unpack_cfl_variant_int64(reader, value); + } + else if (value_type == mpack_type_uint) { + result = unpack_cfl_variant_uint64(reader, value); + } + else if (value_type == mpack_type_double) { + result = unpack_cfl_variant_double(reader, value); + } + else if (value_type == mpack_type_array) { + result = unpack_cfl_variant_array(reader, value); + } + else if (value_type == mpack_type_map) { + result = unpack_cfl_variant_kvlist(reader, value); + } + else if (value_type == mpack_type_bin) { + result = unpack_cfl_variant_binary(reader, value); + } + else { + result = -1; + } + + return result; +} + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctr_version.h.in b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_version.h.in new file mode 100644 index 000000000..4d04118d7 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctr_version.h.in @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_VERSION_H +#define CTR_VERSION_H + +/* Helpers to convert/format version string */ +#define STR_HELPER(s) #s +#define STR(s) STR_HELPER(s) + +/* CTraces Version */ +#define CTR_VERSION_MAJOR @CTR_VERSION_MAJOR@ +#define CTR_VERSION_MINOR @CTR_VERSION_MINOR@ +#define CTR_VERSION_PATCH @CTR_VERSION_PATCH@ +#define CTR_VERSION (CTR_VERSION_MAJOR * 10000 \ + CTR_VERSION_MINOR * 100 \ + CTR_VERSION_PATCH) +#define CTR_VERSION_STR "@CTR_VERSION_STR@" + +char *ctr_version(); + +#endif diff --git a/src/fluent-bit/lib/ctraces/include/ctraces/ctraces.h b/src/fluent-bit/lib/ctraces/include/ctraces/ctraces.h new file mode 100644 index 000000000..0ca02c6f8 --- /dev/null +++ b/src/fluent-bit/lib/ctraces/include/ctraces/ctraces.h @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* CTraces + * ======= + * Copyright 2022 The CTraces Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CTR_H +#define CTR_H + +#define CTR_FALSE 0 +#define CTR_TRUE !CTR_FALSE + +#include <ctraces/ctr_info.h> +#include <ctraces/ctr_compat.h> + +/* local libs */ +#include <cfl/cfl.h> +#include <mpack/mpack.h> + +#include <stdio.h> +#include <stdlib.h> + +/* ctrace options creation keys */ +#define CTR_OPTS_TRACE_ID 0 + +/* options is unused for now */ +struct ctrace_opts { + /* windows compiler: error C2016: C requires that a struct or union have at least one member */ + int _make_windows_happy; +}; + +struct ctrace { + /* + * last_span_id represents the higher span id number assigned, every time + * a new span is created this value gets incremented. + */ + uint64_t last_span_id; + + /* + * When the user creates a new resource, we add it to a linked list so on + * every span we just keep a reference. + */ + struct cfl_list resource_spans; + + /* + * This 'span_list' is used for internal purposes only when a caller needs to + * iterate all spans linearly without getting inside a loop with resource_span, scope_spans, etc. + * + * note: every 'span' is linked to a 'scope_span' and to 'span_list' (this structure) + */ + struct cfl_list span_list; + + /* logging */ + int log_level; + void (*log_cb)(void *, int, const char *, int, const char *); +}; + +struct ctrace *ctr_create(struct ctrace_opts *opts); +void ctr_destroy(struct ctrace *ctx); + +/* options */ +void ctr_opts_init(struct ctrace_opts *opts); +void ctr_opts_set(struct ctrace_opts *opts, int value, char *val); +void ctr_opts_exit(struct ctrace_opts *opts); + +/* headers that are needed in general */ +#include <ctraces/ctr_info.h> +#include <ctraces/ctr_id.h> +#include <ctraces/ctr_random.h> +#include <ctraces/ctr_version.h> +#include <ctraces/ctr_span.h> +#include <ctraces/ctr_scope.h> +#include <ctraces/ctr_link.h> +#include <ctraces/ctr_attributes.h> +#include <ctraces/ctr_log.h> +#include <ctraces/ctr_resource.h> + +/* encoders */ +#include <ctraces/ctr_encode_text.h> +#include <ctraces/ctr_encode_msgpack.h> +#include <ctraces/ctr_encode_opentelemetry.h> + +/* decoders */ +#include <ctraces/ctr_decode_opentelemetry.h> + + + +#endif |