From 7d2cb784a6c45920461112cf4833c73240fac946 Mon Sep 17 00:00:00 2001 From: Maximilian Geberl Date: Wed, 23 Nov 2022 16:35:54 +0100 Subject: [PATCH 1/4] add loadbalancermachine_openstack_info and add new settings to loadbalancer_info --- internal/helper/loadbalancer.go | 12 ++++++++ internal/helper/loadbalancermachine.go | 41 ++++++++++++++++++++++++-- internal/metrics/metrics.go | 30 ++++++++++++------- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/internal/helper/loadbalancer.go b/internal/helper/loadbalancer.go index b18459a4..a56e6c1f 100644 --- a/internal/helper/loadbalancer.go +++ b/internal/helper/loadbalancer.go @@ -327,12 +327,24 @@ func parseLoadBalancerInfoMetric( "isInternal": strconv.FormatBool(lb.Spec.Options.InternalLB), "tcpProxyProtocol": strconv.FormatBool(lb.Spec.Options.TCPProxyProtocol), "externalIP": "nil", + "tcpIdleTimeout": "nil", + "udpIdleTimeout": "nil", + "lokiEnabled": strconv.FormatBool(lb.Spec.Options.LogForward.Enabled), } if lb.Status.ExternalIP != nil { labels["externalIP"] = *lb.Status.ExternalIP } + // TODO wait for merge of other PR + //if lb.Spec.Options.TCPIdleTimeout != nil { + // labels["tcpIdleTimeout"] = *lb.Spec.Options.TCPIdleTimeout + //} + + //if lb.Spec.Options.UDPIdleTimeout != nil { + // labels["udpIdleTimeout"] = *lb.Spec.Options.UDPIdleTimeout + //} + loadbalancerInfoMetric.DeletePartialMatch(map[string]string{"lb": lb.Name, "namespace": lb.Namespace}) loadbalancerInfoMetric.With(labels).Set(1) } diff --git a/internal/helper/loadbalancermachine.go b/internal/helper/loadbalancermachine.go index 71a53b8b..084681ea 100644 --- a/internal/helper/loadbalancermachine.go +++ b/internal/helper/loadbalancermachine.go @@ -57,6 +57,7 @@ func ParseLoadBalancerMachineMetrics( ) { parseLoadBalancerMachineVMMetrics(loadBalancerMachine, metrics) parseLoadBalancerMachineConditionsMetrics(loadBalancerMachine, metrics) + parseLoadBalancerMachineOpenstackInfoMetrics(loadBalancerMachine, metrics) } func parseLoadBalancerMachineVMMetrics( @@ -103,6 +104,38 @@ func parseLoadBalancerMachineConditionsMetrics( } } +func parseLoadBalancerMachineOpenstackInfoMetrics( + loadBalancerMachine *yawolv1beta1.LoadBalancerMachine, + metrics *helpermetrics.LoadBalancerMachineMetricList, +) { + if metrics == nil || metrics.OpenstackInfoMetrics == nil { + return + } + labels := map[string]string{ + "lb": loadBalancerMachine.Spec.LoadBalancerRef.Name, + "lbm": loadBalancerMachine.Name, + "namespace": loadBalancerMachine.Namespace, + "portID": "nil", + "serverID": "nil", + } + + if loadBalancerMachine.Status.PortID != nil { + labels["portID"] = *loadBalancerMachine.Status.PortID + } + + if loadBalancerMachine.Status.ServerID != nil { + labels["serverID"] = *loadBalancerMachine.Status.ServerID + } + + metrics.OpenstackInfoMetrics.DeletePartialMatch(map[string]string{ + "lb": loadBalancerMachine.Spec.LoadBalancerRef.Name, + "lbm": loadBalancerMachine.Name, + "namespace": loadBalancerMachine.Namespace, + }) + metrics.OpenstackInfoMetrics.With(labels).Set(1) + +} + func RemoveLoadBalancerMachineMetrics( loadBalancerMachine *yawolv1beta1.LoadBalancerMachine, metrics *helpermetrics.LoadBalancerMachineMetricList, @@ -112,11 +145,15 @@ func RemoveLoadBalancerMachineMetrics( return } - metrics.VM.DeletePartialMatch(map[string]string{ + labels := map[string]string{ "lb": loadBalancerMachine.Spec.LoadBalancerRef.Name, "lbm": loadBalancerMachine.Name, "namespace": loadBalancerMachine.Namespace, - }) + } + + metrics.VM.DeletePartialMatch(labels) + metrics.Conditions.DeletePartialMatch(labels) + metrics.OpenstackInfoMetrics.DeletePartialMatch(labels) } // RemoveFromLBMStatus removes key from loadbalancermachine status. diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 7f1b2537..867d9e60 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -17,7 +17,7 @@ type LoadBalancerMetricList struct { var LoadBalancerMetrics = LoadBalancerMetricList{ OpenstackMetrics: OpenstackMetrics, InfoMetrics: LoadBalancerInfoMetrics, - OpenstackInfoMetrics: LoadBalancerOpenstackMetrics, + OpenstackInfoMetrics: LoadBalancerOpenstackInfoMetrics, ReplicasMetrics: LoadBalancerReplicasMetrics, ReplicasCurrentMetrics: LoadBalancerReplicasCurrentMetrics, ReplicasReadyMetrics: LoadBalancerReplicasReadyMetrics, @@ -36,15 +36,17 @@ var LoadBalancerSetMetrics = LoadBalancerSetMetricList{ } type LoadBalancerMachineMetricList struct { - VM *prometheus.GaugeVec - Conditions *prometheus.GaugeVec - OpenstackMetrics *prometheus.CounterVec + VM *prometheus.GaugeVec + Conditions *prometheus.GaugeVec + OpenstackMetrics *prometheus.CounterVec + OpenstackInfoMetrics *prometheus.GaugeVec } var LoadBalancerMachineMetrics = LoadBalancerMachineMetricList{ - VM: LoadBalancerMachineVMMetrics, - Conditions: LoadBalancerMachineConditionMetrics, - OpenstackMetrics: OpenstackMetrics, + VM: LoadBalancerMachineVMMetrics, + Conditions: LoadBalancerMachineConditionMetrics, + OpenstackMetrics: OpenstackMetrics, + OpenstackInfoMetrics: LoadBalancerMachineOpenstackInfoMetrics, } var ( @@ -58,9 +60,9 @@ var ( LoadBalancerInfoMetrics = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "loadbalancer_info", Help: "Loadbalancer Info for LoadBalancer contains labels like isInternal, externalIP", - }, []string{"lb", "namespace", "isInternal", "tcpProxyProtocol", "externalIP"}) - // LoadBalancerOpenstackMetrics Openstack Info contains labels with the OpenStackIDs for LoadBalancer - LoadBalancerOpenstackMetrics = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + }, []string{"lb", "namespace", "isInternal", "tcpProxyProtocol", "externalIP", "tcpIdleTimeout", "udpIdleTimeout", "lokiEnabled"}) + // LoadBalancerOpenstackInfoMetrics Openstack Info contains labels with the OpenStackIDs for LoadBalancer + LoadBalancerOpenstackInfoMetrics = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "loadbalancer_openstack_info", Help: "Openstack Info contains labels with the OpenStackIDs for LoadBalancer", }, []string{"lb", "namespace", "portID", "floatingID", "securityGroupID"}) @@ -106,13 +108,18 @@ var ( Name: "loadbalancermachine_condition", Help: "Conditions of loadbalancermachine (lbm.status.conditions)", }, []string{"lb", "lbm", "namespace", "condition", "reason", "status"}) + // LoadBalancerMachineOpenstackInfoMetrics Openstack Info contains labels with the OpenStackIDs for LoadBalancerMachine + LoadBalancerMachineOpenstackInfoMetrics = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "loadbalancermachine_openstack_info", + Help: "Openstack Info contains labels with the OpenStackIDs for LoadBalancerMachine", + }, []string{"lb", "lbm", "namespace", "portID", "serverID"}) ) func init() { // Register custom metrics with the global prometheus registry metrics.Registry.MustRegister(OpenstackMetrics) metrics.Registry.MustRegister(LoadBalancerInfoMetrics) - metrics.Registry.MustRegister(LoadBalancerOpenstackMetrics) + metrics.Registry.MustRegister(LoadBalancerOpenstackInfoMetrics) metrics.Registry.MustRegister(LoadBalancerReplicasMetrics) metrics.Registry.MustRegister(LoadBalancerReplicasCurrentMetrics) metrics.Registry.MustRegister(LoadBalancerReplicasReadyMetrics) @@ -121,4 +128,5 @@ func init() { metrics.Registry.MustRegister(LoadBalancerSetReplicasReadyMetrics) metrics.Registry.MustRegister(LoadBalancerMachineVMMetrics) metrics.Registry.MustRegister(LoadBalancerMachineConditionMetrics) + metrics.Registry.MustRegister(LoadBalancerMachineOpenstackInfoMetrics) } From 5b5b7a477fa1769f9fdf1ba495e65f420033d798 Mon Sep 17 00:00:00 2001 From: Maximilian Geberl Date: Wed, 23 Nov 2022 16:38:54 +0100 Subject: [PATCH 2/4] add new metrics to docs --- docs/components.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/docs/components.md b/docs/components.md index 8e73fe4a..918fd301 100644 --- a/docs/components.md +++ b/docs/components.md @@ -94,19 +94,20 @@ OpenStack instance where the yawollet and Envoy do the actual Load Balancing. The yawol-controller provides some metrics which are exposed via the `/metrics` endpoint. -| metric | description | exposed by | -|----------------------------------|--------------------------------------------------------------------------------------------------|-------------------------------------------------| -| yawol_openstack | Openstack usage counter by api, object, operation | loadbalancer and loadbalancermachine controller | -| loadbalancer_info | Loadbalancer Info for LoadBalancer contains labels like isInternal, externalIP, tcpProxyProtocol | loadbalancer controller | -| loadbalancer_openstack_info | Openstack Info contains labels with the OpenStackIDs for LoadBalancer | loadbalancer controller | -| loadbalancer_replicas | Replicas for LoadBalancer (from lb.spec.replicas) | loadbalancer controller | -| loadbalancer_replicas_current | Current replicas for LoadBalancer (from lb.status.replicas) | loadbalancer controller | -| loadbalancer_replicas_ready | Ready replicas for LoadBalancer (from lb.status.readyReplicas) | loadbalancer controller | -| loadbalancerset_replicas | Replicas for LoadBalancerSet (from lbs.spec.replicas) | loadbalancerset controller | -| loadbalancerset_replicas_current | Current replicas for LoadBalancerSet (from lbs.status.replicas) | loadbalancerset controller | -| loadbalancerset_replicas_ready | Ready replicas for LoadBalancerSet (from lbs.status.readyReplicas) | loadbalancerset controller | -| loadbalancermachine | Metrics of loadbalancermachine (all metrics from lbm.status.metrics) | loadbalancermachine controller | -| loadbalancermachine_condition | Conditions of loadbalancermachine (lbm.status.conditions) | loadbalancermachine controller | +| metric | description | exposed by | +|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------| +| yawol_openstack | Openstack usage counter by api, object, operation | loadbalancer and loadbalancermachine controller | +| loadbalancer_info | Loadbalancer Info for LoadBalancer contains labels like isInternal, externalIP, tcpProxyProtocol, tcpIdleTimeout, udpIdleTimeout, lokiEnabled | loadbalancer controller | +| loadbalancer_openstack_info | Openstack Info contains labels with the OpenStackIDs for LoadBalancer | loadbalancer controller | +| loadbalancer_replicas | Replicas for LoadBalancer (from lb.spec.replicas) | loadbalancer controller | +| loadbalancer_replicas_current | Current replicas for LoadBalancer (from lb.status.replicas) | loadbalancer controller | +| loadbalancer_replicas_ready | Ready replicas for LoadBalancer (from lb.status.readyReplicas) | loadbalancer controller | +| loadbalancerset_replicas | Replicas for LoadBalancerSet (from lbs.spec.replicas) | loadbalancerset controller | +| loadbalancerset_replicas_current | Current replicas for LoadBalancerSet (from lbs.status.replicas) | loadbalancerset controller | +| loadbalancerset_replicas_ready | Ready replicas for LoadBalancerSet (from lbs.status.readyReplicas) | loadbalancerset controller | +| loadbalancermachine | Metrics of loadbalancermachine (all metrics from lbm.status.metrics) | loadbalancermachine controller | +| loadbalancermachine_condition | Conditions of loadbalancermachine (lbm.status.conditions) | loadbalancermachine controller | +| loadbalancermachine_openstack_info | Openstack Info contains labels with the OpenStackIDs for LoadBalancerMachine | loadbalancermachine controller | ## yawollet From c3b2ca6c3788afb80c4acef59c72af27583ee349 Mon Sep 17 00:00:00 2001 From: Maximilian Geberl Date: Wed, 23 Nov 2022 16:53:20 +0100 Subject: [PATCH 3/4] add tcpIdleTimeout and udpIdleTimeout --- internal/helper/loadbalancer.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/helper/loadbalancer.go b/internal/helper/loadbalancer.go index a56e6c1f..95a1f068 100644 --- a/internal/helper/loadbalancer.go +++ b/internal/helper/loadbalancer.go @@ -336,14 +336,13 @@ func parseLoadBalancerInfoMetric( labels["externalIP"] = *lb.Status.ExternalIP } - // TODO wait for merge of other PR - //if lb.Spec.Options.TCPIdleTimeout != nil { - // labels["tcpIdleTimeout"] = *lb.Spec.Options.TCPIdleTimeout - //} - - //if lb.Spec.Options.UDPIdleTimeout != nil { - // labels["udpIdleTimeout"] = *lb.Spec.Options.UDPIdleTimeout - //} + if lb.Spec.Options.TCPIdleTimeout != nil { + labels["tcpIdleTimeout"] = strconv.Itoa(*lb.Spec.Options.TCPIdleTimeout) + } + + if lb.Spec.Options.UDPIdleTimeout != nil { + labels["udpIdleTimeout"] = strconv.Itoa(*lb.Spec.Options.UDPIdleTimeout) + } loadbalancerInfoMetric.DeletePartialMatch(map[string]string{"lb": lb.Name, "namespace": lb.Namespace}) loadbalancerInfoMetric.With(labels).Set(1) From 832d32d851d6c43832c8b95faa150a28f4452e11 Mon Sep 17 00:00:00 2001 From: Maximilian Geberl Date: Thu, 24 Nov 2022 11:05:44 +0100 Subject: [PATCH 4/4] fix linting --- internal/helper/loadbalancermachine.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/helper/loadbalancermachine.go b/internal/helper/loadbalancermachine.go index 084681ea..9dff63a0 100644 --- a/internal/helper/loadbalancermachine.go +++ b/internal/helper/loadbalancermachine.go @@ -133,7 +133,6 @@ func parseLoadBalancerMachineOpenstackInfoMetrics( "namespace": loadBalancerMachine.Namespace, }) metrics.OpenstackInfoMetrics.With(labels).Set(1) - } func RemoveLoadBalancerMachineMetrics(