diff --git a/include/fluent-bit/multiline/flb_ml_parser.h b/include/fluent-bit/multiline/flb_ml_parser.h index c1fbd73bafb..e1c3a52847f 100644 --- a/include/fluent-bit/multiline/flb_ml_parser.h +++ b/include/fluent-bit/multiline/flb_ml_parser.h @@ -52,6 +52,7 @@ struct flb_ml_parser *flb_ml_parser_docker(struct flb_config *config); struct flb_ml_parser *flb_ml_parser_cri(struct flb_config *config); struct flb_ml_parser *flb_ml_parser_java(struct flb_config *config, char *key); struct flb_ml_parser *flb_ml_parser_go(struct flb_config *config, char *key); +struct flb_ml_parser *flb_ml_parser_ruby(struct flb_config *config, char *key); struct flb_ml_parser *flb_ml_parser_python(struct flb_config *config, char *key); #endif diff --git a/src/multiline/CMakeLists.txt b/src/multiline/CMakeLists.txt index 218cf3e7831..294ef3e8fba 100644 --- a/src/multiline/CMakeLists.txt +++ b/src/multiline/CMakeLists.txt @@ -5,6 +5,7 @@ set(src_multiline multiline/flb_ml_parser_python.c multiline/flb_ml_parser_java.c multiline/flb_ml_parser_go.c + multiline/flb_ml_parser_ruby.c # core multiline/flb_ml_stream.c multiline/flb_ml_parser.c diff --git a/src/multiline/flb_ml_parser.c b/src/multiline/flb_ml_parser.c index 2a672605691..46f775d7ccc 100644 --- a/src/multiline/flb_ml_parser.c +++ b/src/multiline/flb_ml_parser.c @@ -69,6 +69,13 @@ int flb_ml_parser_builtin_create(struct flb_config *config) return -1; } + /* Ruby */ + mlp = flb_ml_parser_ruby(config, NULL); + if (!mlp) { + flb_error("[multiline] could not init 'ruby' built-in parser"); + return -1; + } + /* Python */ mlp = flb_ml_parser_python(config, NULL); if (!mlp) { diff --git a/src/multiline/flb_ml_parser_ruby.c b/src/multiline/flb_ml_parser_ruby.c new file mode 100644 index 00000000000..780f829d0eb --- /dev/null +++ b/src/multiline/flb_ml_parser_ruby.c @@ -0,0 +1,87 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +/* Fluent Bit + * ========== + * Copyright (C) 2015-2022 The Fluent Bit 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. + */ + +#include +#include +#include +#include + +#define rule flb_ml_rule_create + +static void rule_error(struct flb_ml_parser *mlp) +{ + int id; + + id = mk_list_size(&mlp->regex_rules); + flb_error("[multiline: ruby] rule #%i could not be created", id); + flb_ml_parser_destroy(mlp); +} + +/* Ruby mode */ +struct flb_ml_parser *flb_ml_parser_ruby(struct flb_config *config, char *key) +{ + int ret; + struct flb_ml_parser *mlp; + + mlp = flb_ml_parser_create(config, /* Fluent Bit context */ + "ruby", /* name */ + FLB_ML_REGEX, /* type */ + NULL, /* match_str */ + FLB_FALSE, /* negate */ + FLB_ML_FLUSH_TIMEOUT, /* flush_ms */ + key, /* key_content */ + NULL, /* key_group */ + NULL, /* key_pattern */ + NULL, /* parser ctx */ + NULL); /* parser name */ + + if (!mlp) { + flb_error("[multiline] could not create 'ruby mode'"); + return NULL; + } + + ret = rule(mlp, + "start_state, ruby_start_exception", + "/^.+:\\d+:in\\s+.*/", + "ruby_after_exception", NULL); + if (ret != 0) { + rule_error(mlp); + return NULL; + } + + ret = rule(mlp, + "ruby_after_exception, ruby", + "/^\\s+from\\s+.*:\\d+:in\\s+.*/", + "ruby", NULL); + if (ret != 0) { + rule_error(mlp); + return NULL; + } + + + /* Map the rules (mandatory for regex rules) */ + ret = flb_ml_parser_init(mlp); + if (ret != 0) { + flb_error("[multiline: ruby] error on mapping rules"); + flb_ml_parser_destroy(mlp); + return NULL; + } + + return mlp; +}