Coverage Report

Created: 2023-03-26 06:05

/src/fluent-bit/src/multiline/flb_ml_parser_cri.c
Line
Count
Source
1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*  Fluent Bit
4
 *  ==========
5
 *  Copyright (C) 2015-2022 The Fluent Bit Authors
6
 *
7
 *  Licensed under the Apache License, Version 2.0 (the "License");
8
 *  you may not use this file except in compliance with the License.
9
 *  You may obtain a copy of the License at
10
 *
11
 *      http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 *  Unless required by applicable law or agreed to in writing, software
14
 *  distributed under the License is distributed on an "AS IS" BASIS,
15
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 *  See the License for the specific language governing permissions and
17
 *  limitations under the License.
18
 */
19
20
#include <fluent-bit/flb_info.h>
21
#include <fluent-bit/multiline/flb_ml.h>
22
#include <fluent-bit/multiline/flb_ml_parser.h>
23
24
#define FLB_ML_CRI_REGEX                                                \
25
447
  "^(?<time>.+?) (?<stream>stdout|stderr) (?<_p>F|P) (?<log>.*)$"
26
#define FLB_ML_CRI_TIME                         \
27
447
  "%Y-%m-%dT%H:%M:%S.%L%z"
28
29
/* Creates a parser for Docker */
30
static struct flb_parser *cri_parser_create(struct flb_config *config)
31
447
{
32
447
    struct flb_parser *p;
33
34
447
    p = flb_parser_create("_ml_cri",               /* parser name */
35
447
                          "regex",                 /* backend type */
36
447
                          FLB_ML_CRI_REGEX,        /* regex */
37
447
                          FLB_FALSE,               /* skip_empty */
38
447
                          FLB_ML_CRI_TIME,         /* time format */
39
447
                          "time",                  /* time key */
40
447
                          NULL,                    /* time offset */
41
447
                          FLB_TRUE,                /* time keep */
42
447
                          FLB_FALSE,               /* time strict */
43
447
                          FLB_FALSE,               /* no bare keys */
44
447
                          NULL,                    /* parser types */
45
447
                          0,                       /* types len */
46
447
                          NULL,                    /* decoders */
47
447
                          config);                 /* Fluent Bit context */
48
447
    return p;
49
447
}
50
51
/* Our first multiline mode: 'docker' */
52
struct flb_ml_parser *flb_ml_parser_cri(struct flb_config *config)
53
447
{
54
447
    struct flb_parser *parser;
55
447
    struct flb_ml_parser *mlp;
56
57
    /* Create a Docker parser */
58
447
    parser = cri_parser_create(config);
59
447
    if (!parser) {
60
2
        return NULL;
61
2
    }
62
63
445
    mlp = flb_ml_parser_create(config,
64
445
                               "cri",                /* name      */
65
445
                               FLB_ML_EQ,            /* type      */
66
445
                               "F",                  /* match_str */
67
445
                               FLB_FALSE,            /* negate    */
68
445
                               FLB_ML_FLUSH_TIMEOUT, /* flush_ms  */
69
445
                               "log",                /* key_content */
70
445
                               "stream",             /* key_group   */
71
445
                               "_p",                 /* key_pattern */
72
445
                               parser,               /* parser ctx  */
73
445
                               NULL);                /* parser name */
74
75
445
    if (!mlp) {
76
4
        flb_error("[multiline] could not create 'cri mode'");
77
4
        return NULL;
78
4
    }
79
80
441
    return mlp;
81
445
}