Skip to content

Commit

Permalink
Add map for log-to-metrics plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Athish Pranav D <[email protected]>
  • Loading branch information
Athishpranav2003 committed Aug 16, 2024
1 parent e470969 commit fc28e76
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apis/fluentbit/v1alpha2/clusterfilter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type FilterItem struct {
AWS *filter.AWS `json:"aws,omitempty"`
// Multiline defines a Multiline configuration.
Multiline *filter.Multiline `json:"multiline,omitempty"`
// LogToMetrics defines a Log to Metrics Filter configuration.
LogToMetrics *filter.LogToMetrics `json:"logToMetrics,omitempty"`
// CustomPlugin defines a Custom plugin configuration.
CustomPlugin *custom.CustomPlugin `json:"customPlugin,omitempty"`
}
Expand Down
112 changes: 112 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/filter/log_to_metrics_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package filter

import (
"fmt"
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins"
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins/params"
)

// +kubebuilder:object:generate:=true

// The Log To Metrics Filter plugin allows you to generate log-derived metrics. <br />
// **For full documentation, refer to https://docs.fluentbit.io/manual/pipeline/filters/log_to_metrics**
type LogToMetrics struct {
plugins.CommonParams `json:",inline"`
// Defines the tag for the generated metrics record
Tag string `json:"tag,omitempty"`
// Optional filter for records in which the content of KEY matches the regular expression.
// Value Format: FIELD REGEX
Regex []string `json:"regex,omitempty"`
// Optional filter for records in which the content of KEY does not matches the regular expression.
// Value Format: FIELD REGEX
Exclude []string `json:"exclude,omitempty"`
// Defines the mode for the metric. Valid values are [counter, gauge or histogram]
MetricMode string `json:"metric_mode,omitempty"`
// Sets the name of the metric.
MetricName string `json:"metric_name,omitempty"`
// Namespace of the metric
MetricNamespace string `json:"metric_namespace,omitempty"`
// Sets a sub-system for the metric.
MetricSubsystem string `json:"metric_subsystem,omitempty"`
// Sets a help text for the metric.
MetricDescription string `json:"metric_description,omitempty"`
// Defines a bucket for histogram
Bucket []string `json:"bucket,omitempty"`
// Add a custom label NAME and set the value to the value of KEY
AddLabel []string `json:"add_label,omitempty"`
// Includes a record field as label dimension in the metric.
LabelField []string `json:"label_field,omitempty"`
// Specify the record field that holds a numerical value
ValueField string `json:"value_field,omitempty"`
// If enabled, it will automatically put pod_id, pod_name, namespace_name, docker_id and container_name
// into the metric as labels. This option is intended to be used in combination with the kubernetes filter plugin.
KubernetesMode *bool `json:"kubernetes_mode,omitempty"`
// Name of the emitter (advanced users)
EmitterName string `json:"emitter_name,omitempty"`
// set a buffer limit to restrict memory usage of metrics emitter
EmitterMemBufLimit string `json:"emitter_mem_limit,omitempty"`
// Flag that defines if logs should be discarded after processing. This applies
// for all logs, no matter if they have emitted metrics or not.
DiscardLogs *bool `json:"discard_logs,omitempty"`
}

func (_ *LogToMetrics) Name() string {
return "log_to_metrics"
}

func (l *LogToMetrics) Params(_ plugins.SecretLoader) (*params.KVs, error) {
kvs := params.NewKVs()
err := g.AddCommonParams(kvs)
if err != nil {
return kvs, err
}
if l.Tag != "" {
kvs.Insert("Tag", l.Tag)
}
for _, reg := range l.Regex {
kvs.Insert("Regex", reg)
}
for _, ex := range l.Exclude {
kvs.Insert("Exclude", ex)
}
if l.MetricMode != "" {
kvs.Insert("Metric_mode", l.MetricMode)
}
if l.MetricName != "" {
kvs.Insert("Metric_name", l.MetricName)
}
if l.MetricNamespace != "" {
kvs.Insert("Metric_namespace", l.MetricNamespace)
}
if l.MetricSubsystem != "" {
kvs.Insert("Metric_subsystem", l.MetricSubsystem)
}
if l.MetricDescription != "" {
kvs.Insert("Metric_description", l.MetricDescription)
}
for _, b := range l.Bucket {
kvs.Insert("Bucket", b)
}
for _, al := range l.AddLabel {
kvs.Insert("Add_label", al)
}
for _, lf := range l.LabelField {
kvs.Insert("Label_field", lf)
}
if l.ValueField != "" {
kvs.Insert("Value_field", l.ValueField)
}
if l.KubernetesMode != nil {
kvs.Insert("Kubernetes_mode", fmt.Sprintf("%t", *l.KubernetesMode))
}
if l.EmitterName != "" {
kvs.Insert("Emitter_Name", l.EmitterName)
}
if l.EmitterMemBufLimit != "" {
kvs.Insert("Emitter_Mem_Buf_Limit", l.EmitterMemBufLimit)
}
if l.DiscardLogs !=nil {
kvs.Insert("Discard_logs", fmt.Sprintf("%t", *l.DiscardLogs))
}
return kvs, nil
}
46 changes: 46 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions apis/fluentbit/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/fluentbit.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ Filter is the Schema for namespace level filter API
| rewriteTag | RewriteTag defines a RewriteTag configuration. | *[filter.RewriteTag](plugins/filter/rewritetag.md) |
| aws | Aws defines a Aws configuration. | *[filter.AWS](plugins/filter/aws.md) |
| multiline | Multiline defines a Multiline configuration. | *[filter.Multiline](plugins/filter/multiline.md) |
| logToMetrics | LogToMetrics defines a Log to Metrics Filter configuration. | *[filter.LogToMetrics](plugins/filter/logtometrics.md) |
| customPlugin | CustomPlugin defines a Custom plugin configuration. | *custom.CustomPlugin |

[Back to TOC](#table-of-contents)
Expand Down Expand Up @@ -635,6 +636,7 @@ ParserSpec defines the desired state of ClusterParser
| emitterName | Per-namespace re-emitter configuration | string |
| emitterMemBufLimit | | string |
| emitterStorageType | | string |
| hotReload | If true enable reloading via HTTP | *bool |

[Back to TOC](#table-of-contents)
# Storage
Expand Down
23 changes: 23 additions & 0 deletions docs/plugins/fluentbit/filter/log_to_metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# LogToMetrics

The Log To Metrics Filter plugin allows you to generate log-derived metrics. <br /> **For full documentation, refer to https://docs.fluentbit.io/manual/pipeline/filters/log_to_metrics**


| Field | Description | Scheme |
| ----- | ----------- | ------ |
| tag | Defines the tag for the generated metrics record | string |
| regex | Optional filter for records in which the content of KEY matches the regular expression. Value Format: FIELD REGEX | []string |
| exclude | Optional filter for records in which the content of KEY does not matches the regular expression. Value Format: FIELD REGEX | []string |
| metric_mode | Defines the mode for the metric. Valid values are [counter, gauge or histogram] | string |
| metric_name | Sets the name of the metric. | string |
| metric_namespace | Namespace of the metric | string |
| metric_subsystem | Sets a sub-system for the metric. | string |
| metric_description | Sets a help text for the metric. | string |
| bucket | Defines a bucket for histogram | []string |
| add_label | Add a custom label NAME and set the value to the value of KEY | []string |
| label_field | Includes a record field as label dimension in the metric. | []string |
| value_field | Specify the record field that holds a numerical value | string |
| kubernetes_mode | If enabled, it will automatically put pod_id, pod_name, namespace_name, docker_id and container_name into the metric as labels. This option is intended to be used in combination with the kubernetes filter plugin. | *bool |
| emitter_name | Name of the emitter (advanced users) | string |
| emitter_mem_limit | set a buffer limit to restrict memory usage of metrics emitter | string |
| discard_logs | Flag that defines if logs should be discarded after processing. This applies for all logs, no matter if they have emitted metrics or not. | bool |
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.23.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.34.1 // indirect
Expand All @@ -74,6 +76,8 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.30.1 // indirect
k8s.io/code-generator v0.30.3 // indirect
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
Expand Down Expand Up @@ -238,6 +240,10 @@ k8s.io/apimachinery v0.30.3 h1:q1laaWCmrszyQuSQCfNB8cFgCuDAoPszKY4ucAjDwHc=
k8s.io/apimachinery v0.30.3/go.mod h1:iexa2somDaxdnj7bha06bhb43Zpa6eWH8N8dbqVjTUc=
k8s.io/client-go v0.30.3 h1:bHrJu3xQZNXIi8/MoxYtZBBWQQXwy16zqJwloXXfD3k=
k8s.io/client-go v0.30.3/go.mod h1:8d4pf8vYu665/kUbsxWAQ/JDBNWqfFeZnvFiVdmx89U=
k8s.io/code-generator v0.30.3 h1:bmtnLJKagDS5f5uOEpLyJiDfIMKXGMKgOLBdde+w0Mc=
k8s.io/code-generator v0.30.3/go.mod h1:PFgBiv+miFV7TZYp+RXgROkhA+sWYZ+mtpbMLofMke8=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo=
k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
Expand Down

0 comments on commit fc28e76

Please sign in to comment.