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

Unexport Format strings #576

Merged
merged 1 commit into from
Feb 20, 2024
Merged

Unexport Format strings #576

merged 1 commit into from
Feb 20, 2024

Conversation

ywwg
Copy link
Contributor

@ywwg ywwg commented Feb 14, 2024

With the addition of the escaping term, format strings now have many permutations and doing direct string comparisons of formats is not reliable. Instead, users should call FormatType and compare the result against the possible enum values.

I am making this change after breaking a test in prometheus that relied on string matching of formats.

With the addition of the escaping term, format strings now have many permutations and doing direct string comparisons of formats is not reliable.
Instead, users should call FormatType and compare the result against the possible enum values.

Signed-off-by: Owen Williams <owen.williams@grafana.com>
Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Let's try it. If this breaks use cases we haven't anticipated, we can still modify or revert.

@beorn7 beorn7 merged commit bd41eb6 into prometheus:main Feb 20, 2024
6 checks passed
@ywwg
Copy link
Contributor Author

ywwg commented Feb 21, 2024

can you do a new library release with this change?

@beorn7
Copy link
Member

beorn7 commented Feb 22, 2024

Ack, will do it ASAP.

@beorn7
Copy link
Member

beorn7 commented Feb 22, 2024

@nicolaasuni-vonage
Copy link

This change breaks an existing workflow:
#577

@ywwg
Copy link
Contributor Author

ywwg commented Feb 23, 2024

@nyetwurk
Copy link

This breaks a lot of things for us... is there an example porting guide?

@ArthurSens
Copy link
Member

This breaks a lot of things for us... is there an example porting guide?

We're currently in the process of cutting a new client_golang release. Client_golang 1.19 should work with common 0.48

return fmtProtoText
case TypeTextPlain:
return fmtText
case TypeOpenMetrics:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to generate a fmtOpenMetrics_0_0_1?

Copy link

@slonka slonka Mar 1, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the new functions in expfmt.go can create these for you: https://github.com/prometheus/common/blob/main/expfmt/expfmt.go#L77

The story is, because the exposition formats are getting more complex, simple string comparison is no longer safe. There are too many equivalent permutations, and therefore things were moved to functions. If the available NewFormat function is not sufficient for your needs, please @ me or file an issue and I can fix it up

Copy link
Contributor

@mrueg mrueg Mar 1, 2024

Choose a reason for hiding this comment

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

Right now TypeOpenMetrics only generates fmtOpenMetrics_1_0_0

If for some reason you need fmtOpenMetrics_0_0_1 there's no way to generate it.

We probably need a TypeOpenMetrics_0_0_1 or an optional version argument for the NewFormat func

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see -- yup I can prep a PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it looks like I should also increase the test coverage -- I'll get to this next week. sorry for the breakage in the meantime!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mrueg please let me know if this approach works for you

#596

roobre added a commit to grafana/synthetic-monitoring-agent that referenced this pull request Mar 5, 2024
roobre added a commit to grafana/synthetic-monitoring-agent that referenced this pull request Mar 5, 2024
metalmatze added a commit to polarsignals/vault that referenced this pull request Mar 6, 2024
The previous exposed constants are no longer exposed and we can use expfmt.Format instead.
prometheus/common#576
peteski22 added a commit to hashicorp/vault that referenced this pull request Mar 14, 2024
* helper/metricsutil: Update usage of expfmt

The previous exposed constants are no longer exposed and we can use expfmt.Format instead.
prometheus/common#576

* reodered imports

---------

Co-authored-by: Matthias Loibl <mail@matthiasloibl.com>
@kylelemons
Copy link

kylelemons commented Jul 12, 2024

The expfmt.FmtText constant appears to be used extensively in Kubernetes.

Now that intermediate libraries are picking this up via client_golang, it is creating headaches for getting dependency trees to converge without replace directives.

Can we get this (at least partially) reverted?

@SuperQ
Copy link
Member

SuperQ commented Jul 14, 2024

@kylelemons I think you may be overestimating the use, most of the results in your search are inline vendor inclusions.

For example, kubernetes/ingress-gce#2600, seems like they have a very broken depdenabot setup that tries to do everything all at once.

@SuperQ
Copy link
Member

SuperQ commented Jul 14, 2024

I can only find one use.

@dnephin
Copy link

dnephin commented Jul 15, 2024

It's used in many places: https://sourcegraph.com/search?q=context:global++expfmt.FmtText+-file:vendor/github.com/prometheus/client_golang+-file:vendor/k8s.io&patternType=keyword&sm=0

The most common one I've seen is

/go/pkg/mod/k8s.io/component-base@v0.30.0/metrics/testutil/metrics.go:73:59: undefined: expfmt.FmtText

Maybe this is fixed in main so it's not showing up in sourcegraph? There is no non-alpha release with the fix.

@ywwg
Copy link
Contributor Author

ywwg commented Jul 15, 2024

@beorn7 it sounds like we could restore expfmt.FmtText as a single const for compatibility, and if people experience issues with escaping / utf-8 they will have to update their code anyway

@nyetwurk
Copy link

@beorn7 it sounds like we could restore expfmt.FmtText as a single const for compatibility, and if people experience issues with escaping / utf-8 they will have to update their code anyway

This is what deprecate is for.
https://stackoverflow.com/questions/7849663/how-do-you-mark-code-as-deprecated-in-go

https://github.com/search?q=repo%3Agolang%2Fgo+Deprecated%3A+language%3AGo&type=code

@SuperQ
Copy link
Member

SuperQ commented Jul 15, 2024

Agreed, this should have been marked deprecated first.

ArthurSens pushed a commit that referenced this pull request Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants