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

Proposal to make http response structs public #571

Closed
jacksontj opened this issue May 8, 2019 · 12 comments
Closed

Proposal to make http response structs public #571

jacksontj opened this issue May 8, 2019 · 12 comments

Comments

@jacksontj
Copy link
Contributor

Reference upstream issue: prometheus/prometheus#3615

TLDR; these http structs are currently private, people use them in a lot of packages -- it would be great if we exposed them so others who want to do their own projects don't have to copy/paste the structs from the prometheus/prometheus project.

Thoughts?

@brian-brazil
Copy link
Contributor

Per that issue, these are internals and I don't think we should encourage users to depend on them and then break when we make changes.

@jacksontj
Copy link
Contributor Author

jacksontj commented May 8, 2019 via email

@brian-brazil
Copy link
Contributor

The API has some guarantees, those structs are internals and do not.

@jacksontj
Copy link
Contributor Author

What are the guarantees on the API? From my understanding its the (1) response codes and (2) response bodies. These structs are just the go representation of the response body. I can understand that you wouldn't want to have clients importing the structs used in the server directly, but I don't see a reason that you wouldn't want to expose them from the go client (since it is doing the same thing).

@brian-brazil
Copy link
Contributor

If client_golang wants to make them public that's a different thing, however I'd hope we'd isolate users of this package from those details.

@jacksontj
Copy link
Contributor Author

If client_golang wants to make them public that's a different thing

This issue is only about client_golang; @krasi-georgiev thoughts?

@krasi-georgiev
Copy link
Contributor

Would you mind giving some code example to illustrate the problem and how it will be solved by exposing these structs?

@jacksontj
Copy link
Contributor Author

@krasi-georgiev
Copy link
Contributor

Thanks.
And can you show an example of how would it look like if these were exported?

I am quite influenced by the talk from William Kenedy which advocates that importing a package should be strictly for its functionality and never for its types.

@jacksontj
Copy link
Contributor Author

If the types were exported these other systems wouldn't need to redefine the structs. So instead of having local struct definitions (which all have to be copied etc.) they could simply import them.

I am quite influenced by the talk from William Kenedy which advocates that importing a package should be strictly for its functionality and never for its types.

In general I'd agree with this, but in this particular case the functionality we are looking for is handling the responses from the HTTP endpoint -- which in go is done by tags in structs. Especially when you look at things like Status and ErrorType those are very similar to stdlib's HTTP status, method, etc. types that it exports.

@krasi-georgiev
Copy link
Contributor

I also see the big benefit for this, but the fact that at the end the users will still import the package just for these exported structs and not for its functionality will cause an additional dependency and limit portability. It is the same as the problem described in this part of the talk which has proven to be a bad idea long term.
I think the Prometheus common package suffers from the same problem.

The benefits of avoiding duplicating types in different packages are great, but isolation and portability is a better argument to keep these unexported I think.

Of course I might be wrong so happy to read more opinions.

@beorn7
Copy link
Member

beorn7 commented Jun 24, 2019

With six weeks of no opinions added here, I'm closing this, as both @krasi-georgiev and @brian-brazil are seeing the trade-off as being better to not export the structs.

Whoever wants to add something new to the debate, please follow up.
To get input from others that haven't seen this issue yet, the prometheus-developers mailing list might be a better forum, though.

@beorn7 beorn7 closed this as completed Jun 24, 2019
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

No branches or pull requests

4 participants