Repository: prometheus/client_golang (Go)

Issue:
Build break after updating
```
./../../go/pkg/mod/github.com/prometheus/client_golang@v1.18.0/prometheus/push/push.go:112:22: undefined: expfmt.FmtProtoDelim
```

Seems to be because of
```
github.com/prometheus/common v0.45.0 => v0.48.0
```

My project has `github.com/snowflakedb/snowflake v1.8.0` which pulls in so many (unwanted) dependencies, including AWS SDK. It seems this break comes in by picking up the AWS sdk v1.25.1.

```
go: upgraded github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.0 => v1.6.1
go: upgraded github.com/aws/aws-sdk-go-v2/credentials v1.17.0 => v1.17.3
go: upgraded github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.16.2 => v1.16.5
go: upgraded github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.0 => v1.3.1
go: upgraded github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.0 => v2.6.1
go: upgraded github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.0 => v1.3.1
go: upgraded github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.0 => v1.11.1
go: upgraded github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.0 => v1.3.1
go: upgraded github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.0 => v1.11.1
go: upgraded github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.0 => v1.17.1
go: upgraded github.com/aws/aws-sdk-go-v2/service/s3 v1.50.1 => v1.51.0
go: upgraded github.com/aws/smithy-go v1.20.0 => v1.20.1
go: upgraded github.com/klauspost/compress v1.17.6 => v1.17.7
go: upgraded github.com/klauspost/cpuid/v2 v2.2.6 => v2.2.7
go: upgraded github.com/prometheus/client_model v0.5.0 => v0.6.0
go: upgraded github.com/prometheus/common v0.45.0 => v0.48.0
go: upgraded golang.org/x/exp v0.0.0-20240213143201-ec583247a57a => v0.0.0-20240222234643-814bf88cf225
go: upgraded google.golang.org/protobuf v1.31.0 => v1.32.0
```

Obviously swimming in all these versions is difficult to diagnose, so I'm not sure what's wrong.

**Update:** looks like the following change made FmtProtoDelim private.

https://github.com/prometheus/common/compare/v0.47.0...v0.48.0



Discussion:
@ywwg is this break from your change? https://github.com/prometheus/common/commit/05d7387306aee31a5a9776899b1baf2267667e81

The same happens when using the `promlint` package:

```
# github.com/prometheus/client_golang/prometheus/testutil/promlint
$HOME/go/pkg/mod/github.com/prometheus/client_golang@v1.18.0/prometheus/testutil/promlint/promlint.go:71:38: undefined: expfmt.FmtText
FAIL	package-operator.run/internal/metrics [build failed]
FAIL
```

Go version: `go version go1.22.0 linux/amd64`
Links to:
- used [go.mod](https://github.com/package-operator/package-operator/blob/7abde923758290e361bdd6aaa31592068a14daf4/go.mod)
- used [go.sum](https://github.com/package-operator/package-operator/blob/7abde923758290e361bdd6aaa31592068a14daf4/go.sum)
Ref.: https://github.com/prometheus/common/issues/577

It looks like this change has to be tagged in order to solve the issue.
Would you please reopen this issue and keep it open until the problem is actually fixed?
Or the issue should be addressed only by prometheus/common https://github.com/prometheus/common/issues/577 ?
There you go!

https://github.com/prometheus/client_golang/releases/tag/v1.19.0
Thank you.



Patch:
diff --git a/go.mod b/go.mod
index 94b9d7974..662608543 100644
--- a/go.mod
+++ b/go.mod
@@ -8,7 +8,7 @@ require (
 	github.com/davecgh/go-spew v1.1.1
 	github.com/json-iterator/go v1.1.12
 	github.com/prometheus/client_model v0.5.0
-	github.com/prometheus/common v0.46.0
+	github.com/prometheus/common v0.48.0
 	github.com/prometheus/procfs v0.12.0
 	golang.org/x/sys v0.16.0
 	google.golang.org/protobuf v1.32.0
diff --git a/go.sum b/go.sum
index 4f1f464ff..450a27317 100644
--- a/go.sum
+++ b/go.sum
@@ -11,7 +11,7 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
 github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
 github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
 github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
-github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
+github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
 github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
@@ -33,8 +33,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
 github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
-github.com/prometheus/common v0.46.0 h1:doXzt5ybi1HBKpsZOL0sSkaNHJJqkyfEWZGGqqScV0Y=
-github.com/prometheus/common v0.46.0/go.mod h1:Tp0qkxpb9Jsg54QMe+EAmqXkSV7Evdy1BTn+g2pa/hQ=
+github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE=
+github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc=
 github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
 github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
 github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
diff --git a/prometheus/push/push.go b/prometheus/push/push.go
index b2c32f429..e524aa130 100644
--- a/prometheus/push/push.go
+++ b/prometheus/push/push.go
@@ -109,7 +109,7 @@ func New(url, job string) *Pusher {
 		gatherers:  prometheus.Gatherers{reg},
 		registerer: reg,
 		client:     &http.Client{},
-		expfmt:     expfmt.FmtProtoDelim,
+		expfmt:     expfmt.NewFormat(expfmt.TypeProtoDelim),
 	}
 }
 


Test patch:
diff --git a/prometheus/push/push_test.go b/prometheus/push/push_test.go
index f90740853..d30d17550 100644
--- a/prometheus/push/push_test.go
+++ b/prometheus/push/push_test.go
@@ -84,7 +84,7 @@ func TestPush(t *testing.T) {
 	}
 
 	buf := &bytes.Buffer{}
-	enc := expfmt.NewEncoder(buf, expfmt.FmtProtoDelim)
+	enc := expfmt.NewEncoder(buf, expfmt.NewFormat(expfmt.TypeProtoDelim))
 
 	for _, mf := range mfs {
 		if err := enc.Encode(mf); err != nil {
diff --git a/prometheus/registry_test.go b/prometheus/registry_test.go
index dca36fe58..61fc1c5cb 100644
--- a/prometheus/registry_test.go
+++ b/prometheus/registry_test.go
@@ -92,7 +92,7 @@ func testHandler(t testing.TB) {
 		},
 	}
 	externalBuf := &bytes.Buffer{}
-	enc := expfmt.NewEncoder(externalBuf, expfmt.FmtProtoDelim)
+	enc := expfmt.NewEncoder(externalBuf, expfmt.NewFormat(expfmt.TypeProtoDelim))
 	if err := enc.Encode(externalMetricFamily); err != nil {
 		t.Fatal(err)
 	}
@@ -162,7 +162,7 @@ metric: <
 		},
 	}
 	buf := &bytes.Buffer{}
-	enc = expfmt.NewEncoder(buf, expfmt.FmtProtoDelim)
+	enc = expfmt.NewEncoder(buf, expfmt.NewFormat(expfmt.TypeProtoDelim))
 	if err := enc.Encode(expectedMetricFamily); err != nil {
 		t.Fatal(err)
 	}
@@ -361,7 +361,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: []byte{},
 			},
@@ -372,7 +372,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: []byte{},
 			},
@@ -383,7 +383,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: []byte{},
 			},
@@ -394,7 +394,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited`,
+					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
 				},
 				body: []byte{},
 			},
@@ -405,7 +405,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: expectedMetricFamilyAsText,
 			},
@@ -417,7 +417,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited`,
+					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
 				},
 				body: expectedMetricFamilyAsBytes,
 			},
@@ -429,7 +429,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: externalMetricFamilyAsText,
 			},
@@ -441,7 +441,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited`,
+					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
 				},
 				body: externalMetricFamilyAsBytes,
 			},
@@ -453,7 +453,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited`,
+					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
 				},
 				body: bytes.Join(
 					[][]byte{
@@ -472,7 +472,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: []byte{},
 			},
@@ -483,7 +483,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: expectedMetricFamilyAsText,
 			},
@@ -495,7 +495,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: bytes.Join(
 					[][]byte{
@@ -514,7 +514,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited`,
+					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited; escaping=values`,
 				},
 				body: bytes.Join(
 					[][]byte{
@@ -533,7 +533,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=text`,
+					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=text; escaping=values`,
 				},
 				body: bytes.Join(
 					[][]byte{
@@ -552,7 +552,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text`,
+					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=values`,
 				},
 				body: bytes.Join(
 					[][]byte{
@@ -571,7 +571,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text`,
+					"Content-Type": `application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=compact-text; escaping=values`,
 				},
 				body: bytes.Join(
 					[][]byte{
@@ -609,7 +609,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: expectedMetricFamilyAsText,
 			},
@@ -666,7 +666,7 @@ collected metric "broken_metric" { label:<name:"foo" value:"bar" > label:<name:"
 			},
 			out: output{
 				headers: map[string]string{
-					"Content-Type": `text/plain; version=0.0.4; charset=utf-8`,
+					"Content-Type": `text/plain; version=0.0.4; charset=utf-8; escaping=values`,
 				},
 				body: bytes.Join(
 					[][]byte{
diff --git a/prometheus/testutil/promlint/promlint.go b/prometheus/testutil/promlint/promlint.go
index dd29cccc3..ea46f38ec 100644
--- a/prometheus/testutil/promlint/promlint.go
+++ b/prometheus/testutil/promlint/promlint.go
@@ -68,7 +68,7 @@ func (l *Linter) Lint() ([]Problem, error) {
 	var problems []Problem
 
 	if l.r != nil {
-		d := expfmt.NewDecoder(l.r, expfmt.FmtText)
+		d := expfmt.NewDecoder(l.r, expfmt.NewFormat(expfmt.TypeTextPlain))
 
 		mf := &dto.MetricFamily{}
 		for {
diff --git a/prometheus/testutil/testutil.go b/prometheus/testutil/testutil.go
index 269f56435..9dce15eaf 100644
--- a/prometheus/testutil/testutil.go
+++ b/prometheus/testutil/testutil.go
@@ -265,13 +265,13 @@ func compareMetricFamilies(got, expected []*dto.MetricFamily, metricNames ...str
 // result.
 func compare(got, want []*dto.MetricFamily) error {
 	var gotBuf, wantBuf bytes.Buffer
-	enc := expfmt.NewEncoder(&gotBuf, expfmt.FmtText)
+	enc := expfmt.NewEncoder(&gotBuf, expfmt.NewFormat(expfmt.TypeTextPlain))
 	for _, mf := range got {
 		if err := enc.Encode(mf); err != nil {
 			return fmt.Errorf("encoding gathered metrics failed: %w", err)
 		}
 	}
-	enc = expfmt.NewEncoder(&wantBuf, expfmt.FmtText)
+	enc = expfmt.NewEncoder(&wantBuf, expfmt.NewFormat(expfmt.TypeTextPlain))
 	for _, mf := range want {
 		if err := enc.Encode(mf); err != nil {
 			return fmt.Errorf("encoding expected metrics failed: %w", err)