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

Add some metrics #72

Merged
merged 4 commits into from
Nov 24, 2022
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
27 changes: 14 additions & 13 deletions docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions internal/helper/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,23 @@ 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
}

if lb.Spec.Options.TCPIdleTimeout != nil {
labels["tcpIdleTimeout"] = strconv.Itoa(*lb.Spec.Options.TCPIdleTimeout)
dergeberl marked this conversation as resolved.
Show resolved Hide resolved
}

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)
}
Expand Down
40 changes: 38 additions & 2 deletions internal/helper/loadbalancermachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func ParseLoadBalancerMachineMetrics(
) {
parseLoadBalancerMachineVMMetrics(loadBalancerMachine, metrics)
parseLoadBalancerMachineConditionsMetrics(loadBalancerMachine, metrics)
parseLoadBalancerMachineOpenstackInfoMetrics(loadBalancerMachine, metrics)
}

func parseLoadBalancerMachineVMMetrics(
Expand Down Expand Up @@ -103,6 +104,37 @@ 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,
Expand All @@ -112,11 +144,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.
Expand Down
30 changes: 19 additions & 11 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type LoadBalancerMetricList struct {
var LoadBalancerMetrics = LoadBalancerMetricList{
OpenstackMetrics: OpenstackMetrics,
InfoMetrics: LoadBalancerInfoMetrics,
OpenstackInfoMetrics: LoadBalancerOpenstackMetrics,
OpenstackInfoMetrics: LoadBalancerOpenstackInfoMetrics,
ReplicasMetrics: LoadBalancerReplicasMetrics,
ReplicasCurrentMetrics: LoadBalancerReplicasCurrentMetrics,
ReplicasReadyMetrics: LoadBalancerReplicasReadyMetrics,
Expand All @@ -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 (
Expand All @@ -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"})
Expand Down Expand Up @@ -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)
Expand All @@ -121,4 +128,5 @@ func init() {
metrics.Registry.MustRegister(LoadBalancerSetReplicasReadyMetrics)
metrics.Registry.MustRegister(LoadBalancerMachineVMMetrics)
metrics.Registry.MustRegister(LoadBalancerMachineConditionMetrics)
metrics.Registry.MustRegister(LoadBalancerMachineOpenstackInfoMetrics)
}