-
Notifications
You must be signed in to change notification settings - Fork 221
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
Add support for prometheus expoter output plugin for fluentbit #840
Merged
benjaminhuo
merged 1 commit into
fluent:master
from
verrazzano:karak/add_prometheus_exporter_output
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
apis/fluentbit/v1alpha2/plugins/output/prometheus_exporter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package output | ||
|
||
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 | ||
|
||
// PrometheusExporter An output plugin to expose Prometheus Metrics. <br /> | ||
// The prometheus exporter allows you to take metrics from Fluent Bit and expose them such that a Prometheus instance can scrape them. <br /> | ||
// **Important Note: The prometheus exporter only works with metric plugins, such as Node Exporter Metrics** <br /> | ||
// **For full documentation, refer to https://docs.fluentbit.io/manual/pipeline/outputs/prometheus-exporter** | ||
type PrometheusExporter struct { | ||
// IP address or hostname of the target HTTP Server, default: 0.0.0.0 | ||
Host string `json:"host"` | ||
// This is the port Fluent Bit will bind to when hosting prometheus metrics. | ||
// +kubebuilder:validation:Minimum:=1 | ||
// +kubebuilder:validation:Maximum:=65535 | ||
Port *int32 `json:"port,omitempty"` | ||
//This allows you to add custom labels to all metrics exposed through the prometheus exporter. You may have multiple of these fields | ||
AddLabels map[string]string `json:"addLabels,omitempty"` | ||
} | ||
|
||
// implement Section() method | ||
func (_ *PrometheusExporter) Name() string { | ||
return "prometheus_exporter" | ||
} | ||
|
||
// implement Section() method | ||
func (p *PrometheusExporter) Params(sl plugins.SecretLoader) (*params.KVs, error) { | ||
kvs := params.NewKVs() | ||
if p.Host != "" { | ||
kvs.Insert("host", p.Host) | ||
} | ||
if p.Port != nil { | ||
kvs.Insert("port", fmt.Sprint(*p.Port)) | ||
} | ||
kvs.InsertStringMap(p.AddLabels, func(k, v string) (string, string) { | ||
return "add_label", fmt.Sprintf(" %s %s", k, v) | ||
}) | ||
return kvs, nil | ||
} |
27 changes: 27 additions & 0 deletions
27
apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
charts/fluent-operator/templates/fluentbit-clusterinput-metrics.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{{- if .Values.fluentbit.enable -}} | ||
{{- if .Values.fluentbit.input.fluentBitMetrics -}} | ||
apiVersion: fluentbit.fluent.io/v1alpha2 | ||
kind: ClusterInput | ||
metadata: | ||
name: fluentbit-metrics | ||
labels: | ||
fluentbit.fluent.io/enabled: "true" | ||
fluentbit.fluent.io/component: logging | ||
spec: | ||
fluentBitMetrics: | ||
{{ toYaml .Values.fluentbit.input.fluentBitMetrics | indent 4}} | ||
{{- end }} | ||
{{- end }} |
15 changes: 15 additions & 0 deletions
15
charts/fluent-operator/templates/fluentbit-output-prometheus-exporter.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{- if .Values.fluentbit.enable -}} | ||
{{- if .Values.fluentbit.output.prometheusMetricsExporter -}} | ||
apiVersion: fluentbit.fluent.io/v1alpha2 | ||
kind: ClusterOutput | ||
metadata: | ||
name: prometheus-exporter | ||
labels: | ||
fluentbit.fluent.io/enabled: "true" | ||
fluentbit.fluent.io/component: logging | ||
spec: | ||
match: {{ .Values.fluentbit.output.prometheusMetricsExporter.match }} | ||
prometheusExporter: | ||
{{ toYaml .Values.fluentbit.output.prometheusMetricsExporter.metricsExporter | indent 4}} | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need to add comments here and in the
values.yaml
that it's recommended to add Prometheus exporter output only when the FluentBit is deployed as a single replica collector mode (A statefulset with 1 replica) because prometheus might scrape duplicated metrics if it's added to the default agent mode (FluentBit DaemonSet)https://github.com/fluent/fluent-operator/blob/master/controllers/collector_controller.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each Fluentbit pod will expose metrics related to itself, and it is probable for multiple pods to share identical metrics while exhibiting distinct values. Typically, customers require to scrape all metrics exposed from each pod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, you're using the Prometheus exporter output to collect metrics of all fluentbit pods. Then it make sense to me. I mean for other cases other than the metrics of fluentbit itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benjaminhuo Let me know, if we are good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, I'm ready to merge