Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Add per environment labels for resources #121

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 16 additions & 2 deletions pkg/metrics/nova.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/prometheus/client_golang/prometheus"
"k8s.io/klog/v2"
"strings"
)

var (
Expand All @@ -22,7 +23,7 @@ var (
// possible server states, from https://github.com/openstack/nova/blob/master/nova/objects/fields.py#L949
states = []string{"ACTIVE", "BUILDING", "PAUSED", "SUSPENDED", "STOPPED", "RESCUED", "RESIZED", "SOFT_DELETED", "DELETED", "ERROR", "SHELVED", "SHELVED_OFFLOADED"}

serverLabels = []string{"id", "name"}
serverLabels = []string{"id", "name", "env", "env_detected"}
)

func registerServerMetrics() {
Expand Down Expand Up @@ -128,7 +129,20 @@ func PublishServerMetrics(client *gophercloud.ServiceClient, tenantID string) er

// publishServerMetric extracts data from a server and exposes the metrics via prometheus
func publishServerMetric(srv servers.Server) {
labels := []string{srv.ID, srv.Name}

// Pick up from OpenStack metadata
environment := ""
if env, exists := srv.Metadata["env"]; exists {
environment = env
}

// We could also use the naming to detect env.
environmentFromName := ""
if strings.Contains(srv.Name, "test-2") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this test-2 string. What do you want to do with this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry so this was a long time ago and (one of) my first pr so it's pretty unclear what the idea is or if it's useful. If I recall correctly the things was we may have multiple clusters for different purposes and the environment is in the name. E g foo-test-1 or foo-test-2. The idea was to provide kosmoo with a list of environments to look for [test-1, test-2] and then check if the name contains one of environments and if so use it.

environmentFromName = "test-2"
}

labels := []string{srv.ID, srv.Name, environment, environmentFromName}

serverVolumeAttachmentCount.WithLabelValues(labels...).Set(float64(len(srv.AttachedVolumes)))
for _, attachedVolumeID := range srv.AttachedVolumes {
Expand Down