Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filterx: otel dict #114

Merged
merged 22 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cab940c
otel: rename LogRecord functions to snake_case
alltilla May 7, 2024
b1de55d
otel: pass const std::string & where possible
alltilla May 7, 2024
41ed14d
otel: add extract_string_from_object() helper fn
alltilla May 7, 2024
bab170d
otel: port LogRecord to implement the Dict interface
alltilla May 7, 2024
3461444
otel: add get_protobuf_message_set_field_count()
alltilla May 7, 2024
17f9228
otel: implement len() for LogRecord
alltilla May 7, 2024
3646630
otel: add Unset() to ProtobufField
alltilla May 7, 2024
9ce814a
otel: implement unset for LogRecord
alltilla May 7, 2024
6442d2f
otel: add IsSet() to ProtobufField
alltilla May 7, 2024
2ed39cd
otel: implement is_key_set for LogRecord
alltilla May 7, 2024
7527ce6
otel: add iter_on_otel_protobuf_message_fields()
alltilla May 7, 2024
45848ae
otel: implement iter() for LogRecord
alltilla May 7, 2024
7a96897
otel: port Resource to implement the Dict interface
alltilla May 7, 2024
0b28f39
otel: implement the rest of the Dict interface for Resource
alltilla May 7, 2024
fe4773e
otel: port Scope to implement the Dict interface
alltilla May 7, 2024
224c2e2
otel: implement the rest of the Dict interface for Scope
alltilla May 7, 2024
641035d
otel: add list and dict factory for Resource, Scope, LogRecord
alltilla May 8, 2024
a3a11ad
filterx: add filterx_dict_merge()
alltilla May 8, 2024
003df12
filterx: add filterx_list_merge()
alltilla May 8, 2024
6af1e67
filterx: use dict merging in json and otel related functions
alltilla May 8, 2024
46ed4e8
filterx: use list merging in json and otel related functions
alltilla May 8, 2024
7808171
filterx: add E2E tests to OTEL Res, Sco, Log <-> JSON convert
alltilla May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/filterx/object-dict-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ filterx_dict_iter(FilterXObject *s, FilterXDictIterFunc func, gpointer user_data
return self->iter(self, func, user_data);
}

static gboolean
_add_elem_to_dict(FilterXObject *key_obj, FilterXObject *value_obj, gpointer user_data)
{
FilterXObject *dict = (FilterXObject *) user_data;

FilterXObject *new_value = filterx_object_ref(value_obj);
gboolean success = filterx_object_set_subscript(dict, key_obj, &new_value);
filterx_object_unref(new_value);

return success;
}

gboolean
filterx_dict_merge(FilterXObject *s, FilterXObject *other)
{
FilterXDict *self = (FilterXDict *) s;

g_assert(filterx_object_is_type(other, &FILTERX_TYPE_NAME(dict)));
return filterx_dict_iter(other, _add_elem_to_dict, self);
}

static gboolean
_len(FilterXObject *s, guint64 *len)
{
Expand Down
1 change: 1 addition & 0 deletions lib/filterx/object-dict-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct FilterXDict_
};

gboolean filterx_dict_iter(FilterXObject *s, FilterXDictIterFunc func, gpointer user_data);
gboolean filterx_dict_merge(FilterXObject *s, FilterXObject *other);

void filterx_dict_init_instance(FilterXDict *self, FilterXType *type);

Expand Down
24 changes: 24 additions & 0 deletions lib/filterx/object-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "filterx/object-null.h"
#include "filterx/object-primitive.h"
#include "filterx/object-string.h"
#include "filterx/object-dict-interface.h"
#include "filterx/object-list-interface.h"
#include "filterx/object-message-value.h"
#include "filterx/filterx-weakrefs.h"
#include "filterx/filterx-eval.h"
Expand Down Expand Up @@ -167,6 +169,28 @@ filterx_json_new_from_args(GPtrArray *args)
filterx_object_is_type(arg, &FILTERX_TYPE_NAME(json_object)))
return filterx_object_ref(arg);

if (filterx_object_is_type(arg, &FILTERX_TYPE_NAME(dict)))
{
FilterXObject *self = filterx_json_object_new_empty();
if (!filterx_dict_merge(self, arg))
{
filterx_object_unref(self);
return NULL;
}
return self;
}

if (filterx_object_is_type(arg, &FILTERX_TYPE_NAME(list)))
{
FilterXObject *self = filterx_json_array_new_empty();
if (!filterx_list_merge(self, arg))
{
filterx_object_unref(self);
return NULL;
}
return self;
}

if (filterx_object_is_type(arg, &FILTERX_TYPE_NAME(message_value)))
{
FilterXObject *unmarshalled = filterx_object_unmarshal(arg);
Expand Down
22 changes: 22 additions & 0 deletions lib/filterx/object-list-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ filterx_list_unset_index(FilterXObject *s, gint64 index)
return result;
}

gboolean
filterx_list_merge(FilterXObject *s, FilterXObject *other)
{
g_assert(filterx_object_is_type(other, &FILTERX_TYPE_NAME(list)));

guint64 len;
g_assert(filterx_object_len(other, &len));

for (guint64 i = 0; i < len; i++)
{
FilterXObject *value_obj = filterx_list_get_subscript(other, (gint64) MIN(i, G_MAXINT64));
gboolean success = filterx_list_append(s, &value_obj);

filterx_object_unref(value_obj);

if (!success)
return FALSE;
}

return TRUE;
}

static gboolean
_len(FilterXObject *s, guint64 *len)
{
Expand Down
1 change: 1 addition & 0 deletions lib/filterx/object-list-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ FilterXObject *filterx_list_get_subscript(FilterXObject *s, gint64 index);
gboolean filterx_list_set_subscript(FilterXObject *s, gint64 index, FilterXObject **new_value);
gboolean filterx_list_append(FilterXObject *s, FilterXObject **new_value);
gboolean filterx_list_unset_index(FilterXObject *s, gint64 index);
gboolean filterx_list_merge(FilterXObject *s, FilterXObject *other);

void filterx_list_init_instance(FilterXList *self, FilterXType *type);

Expand Down
22 changes: 19 additions & 3 deletions modules/grpc/otel/filterx/object-otel-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,27 @@ filterx_otel_array_new_from_args(GPtrArray *args)
try
{
if (!args || args->len == 0)
self->cpp = new Array(self);
{
self->cpp = new Array(self);
}
else if (args->len == 1)
self->cpp = new Array(self, (FilterXObject *) g_ptr_array_index(args, 0));
{
FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0);
if (filterx_object_is_type(arg, &FILTERX_TYPE_NAME(list)))
{
self->cpp = new Array(self);
if (!filterx_list_merge(&self->super.super, arg))
throw std::runtime_error("Failed to merge list");
}
else
{
self->cpp = new Array(self, arg);
}
}
else
throw std::runtime_error("Invalid number of arguments");
{
throw std::runtime_error("Invalid number of arguments");
}
}
catch (const std::runtime_error &e)
{
Expand Down
22 changes: 19 additions & 3 deletions modules/grpc/otel/filterx/object-otel-kvlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,27 @@ filterx_otel_kvlist_new_from_args(GPtrArray *args)
try
{
if (!args || args->len == 0)
self->cpp = new KVList(self);
{
self->cpp = new KVList(self);
}
else if (args->len == 1)
self->cpp = new KVList(self, (FilterXObject *) g_ptr_array_index(args, 0));
{
FilterXObject *arg = (FilterXObject *) g_ptr_array_index(args, 0);
if (filterx_object_is_type(arg, &FILTERX_TYPE_NAME(dict)))
{
self->cpp = new KVList(self);
if (!filterx_dict_merge(&self->super.super, arg))
throw std::runtime_error("Failed to merge dict");
}
else
{
self->cpp = new KVList(self, arg);
}
}
else
throw std::runtime_error("Invalid number of arguments");
{
throw std::runtime_error("Invalid number of arguments");
}
}
catch (const std::runtime_error &e)
{
Expand Down
Loading
Loading