Repository: prometheus/prometheus (language: go)

Issue:
promql: `label_join` destination label is not validated (v2.51.0+)
### What did you do?

Do a query:
```promql
label_join(demo_num_cpus, "~invalid", "-", "instance")
```



### What did you expect to see?

Query should fail.

Prometheus v2.50.1:
```
invalid destination label name in label_join(): ~invalid
```

### What did you see instead? Under which circumstances?

Successful response with label `~invalid`.

I believe commit https://github.com/prometheus/prometheus/commit/fdd5b85e06c3bd451af32906a185748bf451e35c caused the issue.

### System information

Linux 6.2.0-39-generic x86_64

### Prometheus version

```text
prometheus, version 2.51.0 (branch: HEAD, revision: c05c15512acb675e3f6cd662a6727854e93fc024)
  build user:       root@b5723e458358
  build date:       20240319-10:54:45
  go version:       go1.22.1
  platform:         linux/amd64
  tags:             netgo,builtinassets,stringlabels
```


### Prometheus configuration file

_No response_

### Alertmanager version

_No response_

### Alertmanager configuration file

_No response_

### Logs

_No response_


Discussion / hints:

Fix patch:
diff --git a/promql/functions.go b/promql/functions.go
index da66af2f025..d5840374e77 100644
--- a/promql/functions.go
+++ b/promql/functions.go
@@ -1386,6 +1386,9 @@ func (ev *evaluator) evalLabelJoin(args parser.Expressions) (parser.Value, annot
 		}
 		srcLabels[i-3] = src
 	}
+	if !model.LabelName(dst).IsValid() {
+		panic(fmt.Errorf("invalid destination label name in label_join(): %s", dst))
+	}
 
 	val, ws := ev.eval(args[0])
 	matrix := val.(Matrix)


Test patch: