Skip to content

Commit

Permalink
Add fluentd-windows prometheus metrics support (#2931)
Browse files Browse the repository at this point in the history
* Add fluentd-windows prometheus metrics support

Also a small fix to calico-node-windows prometheus metrics.

* Address review comments

* Further fix indentation.
  • Loading branch information
coutinhop authored Oct 16, 2023
1 parent 0a051d0 commit 077f748
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/installation/windows_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (r *ReconcileWindows) Reconcile(ctx context.Context, request reconcile.Requ
}

// The key pair is created by the core controller, so if it isn't set, requeue to wait until it is
nodePrometheusTLS, err = certificateManager.GetKeyPair(r.client, render.NodePrometheusTLSServerSecret, common.OperatorNamespace(), dns.GetServiceDNSNames(render.CalicoNodeMetricsService, common.CalicoNamespace, r.clusterDomain))
nodePrometheusTLS, err = certificateManager.GetKeyPair(r.client, render.NodePrometheusTLSServerSecret, common.OperatorNamespace(), dns.GetServiceDNSNames(render.WindowsNodeMetricsService, common.CalicoNamespace, r.clusterDomain))
if err != nil {
r.status.SetDegraded(operatorv1.ResourceCreateError, "Error getting TLS certificate", err, reqLogger)
return reconcile.Result{}, err
Expand Down
23 changes: 15 additions & 8 deletions pkg/render/fluentd.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
// use-case for this credential. However, it is used on all TLS connections served by fluentd.
FluentdPrometheusTLSSecretName = "tigera-fluentd-prometheus-tls"
FluentdMetricsService = "fluentd-metrics"
FluentdMetricsServiceWindows = "fluentd-metrics-windows"
FluentdMetricsPortName = "fluentd-metrics-port"
FluentdMetricsPort = 9081
FluentdPolicyName = networkpolicy.TigeraComponentPolicyPrefix + "allow-fluentd-node"
Expand Down Expand Up @@ -214,6 +215,16 @@ func (c *fluentdComponent) fluentdNodeName() string {
return FluentdNodeName
}

// Use different service names depending on the OS type ("fluentd-metrics"
// vs "fluentd-metrics-windows") in order to help identify which OS daemonset
// we are referring to.
func (c *fluentdComponent) fluentdMetricsServiceName() string {
if c.cfg.OSType == rmeta.OSTypeWindows {
return FluentdMetricsServiceWindows
}
return FluentdMetricsService
}

func (c *fluentdComponent) readinessCmd() []string {
if c.cfg.OSType == rmeta.OSTypeWindows {
// On Windows, we rely on bash via msys2 installed by the fluentd base image.
Expand Down Expand Up @@ -584,12 +595,12 @@ func (c *fluentdComponent) metricsService() *corev1.Service {
return &corev1.Service{
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
ObjectMeta: metav1.ObjectMeta{
Name: FluentdMetricsService,
Name: c.fluentdMetricsServiceName(),
Namespace: LogCollectorNamespace,
Labels: map[string]string{"k8s-app": FluentdNodeName},
Labels: map[string]string{"k8s-app": c.fluentdNodeName()},
},
Spec: corev1.ServiceSpec{
Selector: map[string]string{"k8s-app": FluentdNodeName},
Selector: map[string]string{"k8s-app": c.fluentdNodeName()},
// Important: "None" tells Kubernetes that we want a headless service with
// no kube-proxy load balancer. If we omit this then kube-proxy will render
// a huge set of iptables rules for this service since there's an instance
Expand Down Expand Up @@ -795,13 +806,9 @@ func (c *fluentdComponent) envvars() []corev1.EnvVar {
corev1.EnvVar{Name: "ELASTIC_WAF_INDEX_SHARDS", Value: strconv.Itoa(c.cfg.ESClusterConfig.Shards())},
corev1.EnvVar{Name: "ELASTIC_L7_INDEX_SHARDS", Value: strconv.Itoa(c.cfg.ESClusterConfig.Shards())},
corev1.EnvVar{Name: "ELASTIC_RUNTIME_INDEX_SHARDS", Value: strconv.Itoa(c.cfg.ESClusterConfig.Shards())},
corev1.EnvVar{Name: "CA_CRT_PATH", Value: c.trustedBundlePath()},
)

if c.SupportedOSType() != rmeta.OSTypeWindows {
envs = append(envs,
corev1.EnvVar{Name: "CA_CRT_PATH", Value: c.cfg.TrustedBundle.MountPath()},
)
}
return envs
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/render/fluentd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ var _ = Describe("Tigera Secure Fluentd rendering tests", func() {
}{
{name: "tigera-fluentd", ns: "", group: "", version: "v1", kind: "Namespace"},
{name: render.FluentdPolicyName, ns: render.LogCollectorNamespace, group: "projectcalico.org", version: "v3", kind: "NetworkPolicy"},
{name: render.FluentdMetricsService, ns: render.LogCollectorNamespace, group: "", version: "v1", kind: "Service"},
{name: render.FluentdMetricsServiceWindows, ns: render.LogCollectorNamespace, group: "", version: "v1", kind: "Service"},
{name: "tigera-fluentd-windows", ns: "", group: "rbac.authorization.k8s.io", version: "v1", kind: "ClusterRole"},
{name: "tigera-fluentd-windows", ns: "", group: "rbac.authorization.k8s.io", version: "v1", kind: "ClusterRoleBinding"},
{name: "fluentd-node-windows", ns: "tigera-fluentd", group: "", version: "v1", kind: "ServiceAccount"},
Expand Down
20 changes: 18 additions & 2 deletions pkg/render/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,15 @@ func (mc *monitorComponent) serviceMonitorCalicoNode() *monitoringv1.ServiceMoni
Labels: map[string]string{"team": "network-operators"},
},
Spec: monitoringv1.ServiceMonitorSpec{
Selector: metav1.LabelSelector{MatchLabels: map[string]string{"k8s-app": "calico-node"}},
Selector: metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "k8s-app",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"calico-node", "calico-node-windows"},
},
},
},
NamespaceSelector: monitoringv1.NamespaceSelector{MatchNames: []string{"calico-system"}},
Endpoints: []monitoringv1.Endpoint{
{
Expand Down Expand Up @@ -815,7 +823,15 @@ func (mc *monitorComponent) serviceMonitorFluentd() *monitoringv1.ServiceMonitor
Labels: map[string]string{"team": "network-operators"},
},
Spec: monitoringv1.ServiceMonitorSpec{
Selector: metav1.LabelSelector{MatchLabels: map[string]string{"k8s-app": "fluentd-node"}},
Selector: metav1.LabelSelector{
MatchExpressions: []metav1.LabelSelectorRequirement{
{
Key: "k8s-app",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"fluentd-node", "fluentd-node-windows"},
},
},
},
NamespaceSelector: monitoringv1.NamespaceSelector{MatchNames: []string{render.LogCollectorNamespace}},
Endpoints: []monitoringv1.Endpoint{
{
Expand Down
31 changes: 25 additions & 6 deletions pkg/render/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,15 @@ var _ = Describe("monitor rendering tests", func() {
Expect(ok).To(BeTrue())
Expect(servicemonitorObj.ObjectMeta.Labels).To(HaveLen(1))
Expect(servicemonitorObj.ObjectMeta.Labels["team"]).To(Equal("network-operators"))
Expect(servicemonitorObj.Spec.Selector.MatchLabels).To(HaveLen(1))
Expect(servicemonitorObj.Spec.Selector.MatchLabels["k8s-app"]).To(Equal("fluentd-node"))
Expect(servicemonitorObj.Spec.Selector.MatchLabels).To(HaveLen(0))
Expect(servicemonitorObj.Spec.Selector.MatchExpressions).To(HaveLen(1))
Expect(servicemonitorObj.Spec.Selector.MatchExpressions).To(ConsistOf([]metav1.LabelSelectorRequirement{
{
Key: "k8s-app",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"fluentd-node", "fluentd-node-windows"},
},
}))
Expect(servicemonitorObj.Spec.NamespaceSelector.MatchNames).To(HaveLen(1))
Expect(servicemonitorObj.Spec.NamespaceSelector.MatchNames[0]).To(Equal("tigera-fluentd"))
Expect(servicemonitorObj.Spec.Endpoints).To(HaveLen(1))
Expand Down Expand Up @@ -444,8 +451,13 @@ var _ = Describe("monitor rendering tests", func() {
Expect(ok).To(BeTrue())
Expect(servicemonitorObj.ObjectMeta.Labels).To(HaveLen(1))
Expect(servicemonitorObj.ObjectMeta.Labels["team"]).To(Equal("network-operators"))
Expect(servicemonitorObj.Spec.Selector.MatchLabels).To(HaveLen(1))
Expect(servicemonitorObj.Spec.Selector.MatchLabels["k8s-app"]).To(Equal("calico-node"))
Expect(servicemonitorObj.Spec.Selector.MatchLabels).To(HaveLen(0))
Expect(servicemonitorObj.Spec.Selector.MatchExpressions).To(HaveLen(1))
Expect(servicemonitorObj.Spec.Selector.MatchExpressions).To(ConsistOf([]metav1.LabelSelectorRequirement{
{Key: "k8s-app",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"calico-node", "calico-node-windows"}},
}))
Expect(servicemonitorObj.Spec.NamespaceSelector.MatchNames).To(HaveLen(1))
Expect(servicemonitorObj.Spec.NamespaceSelector.MatchNames[0]).To(Equal("calico-system"))
Expect(servicemonitorObj.Spec.Endpoints).To(HaveLen(2))
Expand Down Expand Up @@ -475,8 +487,15 @@ var _ = Describe("monitor rendering tests", func() {

servicemonitorObj, ok = rtest.GetResource(toCreate, "fluentd-metrics", common.TigeraPrometheusNamespace, "monitoring.coreos.com", "v1", monitoringv1.ServiceMonitorsKind).(*monitoringv1.ServiceMonitor)
Expect(ok).To(BeTrue())
Expect(servicemonitorObj.Spec.Selector.MatchLabels).To(HaveLen(1))
Expect(servicemonitorObj.Spec.Selector.MatchLabels["k8s-app"]).To(Equal("fluentd-node"))
Expect(servicemonitorObj.Spec.Selector.MatchLabels).To(HaveLen(0))
Expect(servicemonitorObj.Spec.Selector.MatchExpressions).To(HaveLen(1))
Expect(servicemonitorObj.Spec.Selector.MatchExpressions).To(ConsistOf([]metav1.LabelSelectorRequirement{
{
Key: "k8s-app",
Operator: metav1.LabelSelectorOpIn,
Values: []string{"fluentd-node", "fluentd-node-windows"},
},
}))
Expect(servicemonitorObj.Spec.NamespaceSelector.MatchNames).To(HaveLen(1))
Expect(servicemonitorObj.Spec.NamespaceSelector.MatchNames[0]).To(Equal("tigera-fluentd"))
Expect(servicemonitorObj.Spec.Endpoints).To(HaveLen(1))
Expand Down

0 comments on commit 077f748

Please sign in to comment.