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

feat: add ability to customize metrics port #587

Merged
merged 2 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions apis/fluentbit/v1alpha2/fluentbit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type FluentBitSpec struct {
// Set DNS policy for the pod. Defaults to "ClusterFirst". Valid values are
// 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'.
DNSPolicy corev1.DNSPolicy `json:"dnsPolicy,omitempty"`
// MetricsPort is the port used by the metrics server. If this option is set, HttpPort from ClusterFluentBitConfig needs to match this value. Default is 2020.
MetricsPort int32 `json:"metricsPort,omitempty"`
}

// FluentBitStatus defines the observed state of FluentBit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,10 @@ spec:
format: int32
type: integer
type: object
metricsPort:
description: Set the port used by the metrics server
format: int32
type: integer
nodeSelector:
additionalProperties:
type: string
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/fluentbit.fluent.io_fluentbits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,10 @@ spec:
format: int32
type: integer
type: object
metricsPort:
description: Set the port used by the metrics server
format: int32
type: integer
nodeSelector:
additionalProperties:
type: string
Expand Down
1 change: 1 addition & 0 deletions docs/fluentbit.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ FluentBitSpec defines the desired state of FluentBit
| ports | Ports represents the pod's ports. | []corev1.ContainerPort |
| rbacRules | RBACRules represents additional rbac rules which will be applied to the fluent-bit clusterrole. | []rbacv1.PolicyRule |
| dnsPolicy | Set DNS policy for the pod. Defaults to \"ClusterFirst\". Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'. | corev1.DNSPolicy |
| metricsPort | MetricsPort is the port used by the metrics server. If this option is set, HttpPort from ClusterFluentBitConfig needs to match this value. Default is 2020. | int32 |

[Back to TOC](#table-of-contents)
# InputSpec
Expand Down
10 changes: 9 additions & 1 deletion pkg/operator/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ func MakeDaemonSet(fb fluentbitv1alpha2.FluentBit, logPath string) appsv1.Daemon
} else {
labels = fb.Labels
}

var metricsPort int32
if fb.Spec.MetricsPort != 0 {
metricsPort = fb.Spec.MetricsPort
} else {
metricsPort = 2020
}

ds := appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: fb.Name,
Expand Down Expand Up @@ -81,7 +89,7 @@ func MakeDaemonSet(fb fluentbitv1alpha2.FluentBit, logPath string) appsv1.Daemon
Ports: []corev1.ContainerPort{
{
Name: "metrics",
ContainerPort: 2020,
ContainerPort: metricsPort,
Protocol: "TCP",
},
},
Expand Down
11 changes: 9 additions & 2 deletions pkg/operator/fluent-bit-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ import (

const (
FluentBitMetricsPortName = "metrics"
FluentBitMetricsPort = 2020
FluentBitTCPProtocolName = "TCP"
)

func MakeFluentbitService(fb fluentbitv1alpha2.FluentBit) corev1.Service {

var FluentBitMetricsPort int32
if fb.Spec.MetricsPort != 0 {
FluentBitMetricsPort = fb.Spec.MetricsPort
} else {
FluentBitMetricsPort = 2020
}

svc := corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: fb.Name,
Expand All @@ -29,7 +36,7 @@ func MakeFluentbitService(fb fluentbitv1alpha2.FluentBit) corev1.Service {
Name: FluentBitMetricsPortName,
Port: FluentBitMetricsPort,
Protocol: FluentBitTCPProtocolName,
TargetPort: intstr.FromInt(FluentBitMetricsPort),
TargetPort: intstr.FromInt(int(FluentBitMetricsPort)),
},
},
},
Expand Down