From 150652e939dc383619cd112673f3f18d12d3ee10 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ho=C3=A0ng=20=C4=90=E1=BB=A9c=20Hi=E1=BA=BFu?=
 <code@hdhoang.space>
Date: Fri, 11 Feb 2022 13:46:36 +0700
Subject: [PATCH 1/2] poll: fix swapped machine<->namespace labels

---
 poll.go | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/poll.go b/poll.go
index bcd6c33f..dd3956fb 100644
--- a/poll.go
+++ b/poll.go
@@ -193,7 +193,7 @@ func (h *Headscale) PollNetMapHandler(ctx *gin.Context) {
 
 		// It sounds like we should update the nodes when we have received a endpoint update
 		// even tho the comments in the tailscale code dont explicitly say so.
-		updateRequestsFromNode.WithLabelValues(machine.Name, machine.Namespace.Name, "endpoint-update").
+		updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Name, "endpoint-update").
 			Inc()
 		updateChan <- struct{}{}
 
@@ -222,7 +222,7 @@ func (h *Headscale) PollNetMapHandler(ctx *gin.Context) {
 		Str("handler", "PollNetMap").
 		Str("machine", machine.Name).
 		Msg("Notifying peers")
-	updateRequestsFromNode.WithLabelValues(machine.Name, machine.Namespace.Name, "full-update").
+	updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Name, "full-update").
 		Inc()
 	updateChan <- struct{}{}
 
@@ -413,7 +413,7 @@ func (h *Headscale) PollNetMapStream(
 				Str("machine", machine.Name).
 				Str("channel", "update").
 				Msg("Received a request for update")
-			updateRequestsReceivedOnChannel.WithLabelValues(machine.Name, machine.Namespace.Name).
+			updateRequestsReceivedOnChannel.WithLabelValues(machine.Namespace.Name, machine.Name).
 				Inc()
 			if h.isOutdated(machine) {
 				var lastUpdate time.Time
@@ -443,7 +443,7 @@ func (h *Headscale) PollNetMapStream(
 						Str("channel", "update").
 						Err(err).
 						Msg("Could not write the map response")
-					updateRequestsSentToNode.WithLabelValues(machine.Name, machine.Namespace.Name, "failed").
+					updateRequestsSentToNode.WithLabelValues(machine.Namespace.Name, machine.Name, "failed").
 						Inc()
 
 					return false
@@ -453,7 +453,7 @@ func (h *Headscale) PollNetMapStream(
 					Str("machine", machine.Name).
 					Str("channel", "update").
 					Msg("Updated Map has been sent")
-				updateRequestsSentToNode.WithLabelValues(machine.Name, machine.Namespace.Name, "success").
+				updateRequestsSentToNode.WithLabelValues(machine.Namespace.Name, machine.Name, "success").
 					Inc()
 
 				// Keep track of the last successful update,
@@ -582,7 +582,7 @@ func (h *Headscale) scheduledPollWorker(
 				Str("func", "scheduledPollWorker").
 				Str("machine", machine.Name).
 				Msg("Sending update request")
-			updateRequestsFromNode.WithLabelValues(machine.Name, machine.Namespace.Name, "scheduled-update").
+			updateRequestsFromNode.WithLabelValues(machine.Namespace.Name, machine.Name, "scheduled-update").
 				Inc()
 			updateChan <- struct{}{}
 		}

From 66ff34c2ddb2ca34dcee3a3aa49b14754aeb0591 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ho=C3=A0ng=20=C4=90=E1=BB=A9c=20Hi=E1=BA=BFu?=
 <code@hdhoang.space>
Date: Fri, 11 Feb 2022 13:49:09 +0700
Subject: [PATCH 2/2] apply changelog

---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6c74144e..a4a56faf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
 **Changes**:
 
 - `ip_prefix` is now superseded by `ip_prefixes` in the configuration [#208](https://github.com/juanfont/headscale/pull/208)
+- fix swapped machine<->namespace labels in `/metrics` 
 
 **0.12.4 (2022-01-29):**