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

Expose Thanos HTTP APIs to OpenAPI/protobuf Proposal #4426

Merged
merged 7 commits into from
Jul 29, 2021

Conversation

Hangzhi
Copy link
Contributor

@Hangzhi Hangzhi commented Jul 8, 2021

Signed-off-by: Hangzhi [email protected]

Related to : #4102

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Verification

bwplotka
bwplotka previously approved these changes Jul 8, 2021
Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Nice, great work! I love it, LGTM 💪🏽

@@ -0,0 +1,73 @@
| type | title | status | menu |
Copy link
Member

Choose a reason for hiding this comment

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

I think we use different format of front matter - hopefully we can get rid of this too, but right now it's required to be yaml between --- letters.


## **Motivations**

In order to improve Thanos usage for users, we would like to define our HTTP APIs in protobuf/OpenAPI and expose those in the website. This would allow users to use tools for documentation, validation, type checking, and even code generation to use our APIs efficiently.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In order to improve Thanos usage for users, we would like to define our HTTP APIs in protobuf/OpenAPI and expose those in the website. This would allow users to use tools for documentation, validation, type checking, and even code generation to use our APIs efficiently.
In order to improve Thanos usage for users, we would like to define our HTTP APIs in protobuf/OpenAPI and expose those in our repository. This would allow users to use tools for documentation, validation, type checking, and even code generation to use our APIs efficiently.
Similarly we want reuse this work in Prometheus.

Copy link
Contributor

Choose a reason for hiding this comment

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

For readability it would be good to expand on the following parts:

  • In order to improve Thanos usage for users - what do we mean by improve here? What positive benefit will this bring to users?
  • protobuf/OpenAPI - as far as I am aware these are two different & non-interchangeable things?


### **Pitfalls of the current solution**

- Documentation needs to be written manually.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Documentation needs to be written manually.
- Documentation, Server code and client code boilerplate needs to be written manually.
- It's hard to discover the current API programmatically.
- It's easy to make an accidental breaking changes when modifying API

Copy link
Contributor

Choose a reason for hiding this comment

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

I would reword the final point to be something like

When modifying the API, it is very difficult to know if this breaks downstream users

Or similar :)

- Be able to generate OpenAPI3 from protobuf.
- Auto-generate documentation with OpenAPI3 specification.
- Generate server code from API specification (OpenAPI3 or protobuf).
- Define all configuration potentially in protobuf too: https://github.com/openproto/protoconfig.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can drop that to focus more on APIs in this phase (:


## **Non-Goals**

- Not define Thanos gRPC APIs in protobuf specification.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Not define Thanos gRPC APIs in protobuf specification.
- Don't mix gRPC with HTTP APIs in same protobuf package


## **How**

- Define Thanos APIs in protobuf specification.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Define Thanos APIs in protobuf specification.
- Define Thanos HTTP APIs in protobuf specification.

- Define Thanos APIs in protobuf specification.
- Generate OpenAPI from protobuf with gnostic extension.
- Generate documentation from OpenAPI with [swagger](https://github.com/swagger-api/swagger-codegen).
- Generate server API client and server stubs potentially from OpenAPI with [swagger](https://github.com/swagger-api/swagger-codegen) or [oapi-codegen](https://github.com/deepmap/oapi-codegen).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Generate server API client and server stubs potentially from OpenAPI with [swagger](https://github.com/swagger-api/swagger-codegen) or [oapi-codegen](https://github.com/deepmap/oapi-codegen).
- Generate server and client API stubs potentially from OpenAPI with [swagger](https://github.com/swagger-api/swagger-codegen) or [oapi-codegen](https://github.com/deepmap/oapi-codegen).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a big fan of having 'potentially' in proposals - we're either going to do it or not :)


## **Alternatives**

## **Only define HTTP RESTful API only in OpenAPI. Not in protobuf.**
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## **Only define HTTP RESTful API only in OpenAPI. Not in protobuf.**
## **Define HTTP RESTful API only in OpenAPI. Not in protobuf.**

## **Only define HTTP RESTful API only in OpenAPI. Not in protobuf.**

1. Pros:
1. We are not sure whether we can definitely generate OpenAPI specifications from protobuf.
Copy link
Member

Choose a reason for hiding this comment

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

  • There are might be some complexity, edge case and extra tooling to make 3 step process (proto -> open API -> documentation to work

1. We can have gRPC and RESTful APIs at the same time.
2. We have gRPC APIs like rules API.
2. Cons:
1. We don't know clearly how grpc-gateway works.
Copy link
Member

Choose a reason for hiding this comment

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

  • We need run another sidecar (complexity of running the system)
  • Semantics of gRPC and HTTP might be different and surprising for end user.
  • We want to reuse in Prometheus and Prometheus does not support gRPC (gRPC dependency was removed from codebase)
  • Same port library is not maintained. (cmux)

@bill3tt
Copy link
Contributor

bill3tt commented Jul 8, 2021

@Hangzhi make check-docs to see what is causing CI to fail.

Copy link
Contributor

@bill3tt bill3tt left a comment

Choose a reason for hiding this comment

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

Looks good - the content is good, but I think our motivations can be better explained.


## **Motivations**

In order to improve Thanos usage for users, we would like to define our HTTP APIs in protobuf/OpenAPI and expose those in the website. This would allow users to use tools for documentation, validation, type checking, and even code generation to use our APIs efficiently.
Copy link
Contributor

Choose a reason for hiding this comment

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

For readability it would be good to expand on the following parts:

  • In order to improve Thanos usage for users - what do we mean by improve here? What positive benefit will this bring to users?
  • protobuf/OpenAPI - as far as I am aware these are two different & non-interchangeable things?


### **Pitfalls of the current solution**

- Documentation needs to be written manually.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would reword the final point to be something like

When modifying the API, it is very difficult to know if this breaks downstream users

Or similar :)

Comment on lines 31 to 35
- Define all APIs in protobuf.
- Be able to generate OpenAPI3 from protobuf.
- Auto-generate documentation with OpenAPI3 specification.
- Generate server code from API specification (OpenAPI3 or protobuf).
- Define all configuration potentially in protobuf too: https://github.com/openproto/protoconfig.
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO these are not goals per-se but the steps we take to satisfy the goals - in fact, they are very similar to the How section below.

I think the goals here is to make the Thanos APIs easier to share, document and consume?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ianbillett Thank you for your great reviews. Yes, make the Thanos APIs easier to share, document and consume seems like a better phrase. But in LFX mentorship program, I think we need a clear goal to decide whether this project is accepted. This goal seems to be vague and hard to quantify. 😃

- Define Thanos APIs in protobuf specification.
- Generate OpenAPI from protobuf with gnostic extension.
- Generate documentation from OpenAPI with [swagger](https://github.com/swagger-api/swagger-codegen).
- Generate server API client and server stubs potentially from OpenAPI with [swagger](https://github.com/swagger-api/swagger-codegen) or [oapi-codegen](https://github.com/deepmap/oapi-codegen).
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a big fan of having 'potentially' in proposals - we're either going to do it or not :)

Hangzhi added 3 commits July 20, 2021 19:21
Signed-off-by: Hangzhi <[email protected]>
Signed-off-by: Hangzhi <[email protected]>
Signed-off-by: Hangzhi <[email protected]>
@Hangzhi
Copy link
Contributor Author

Hangzhi commented Jul 22, 2021

Hello @ianbillett. The test shows that the file is not formatted, but it's not clear how not formatted. And it results in errors in the e2e test, though this PR should not involve the e2e test 🤔 . Do you have any hints on how I can resolve these errors?

onprem
onprem previously approved these changes Jul 22, 2021
Copy link
Member

@onprem onprem left a comment

Choose a reason for hiding this comment

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

Looking good to me, just some small non-blocker nits.

@bill3tt
Copy link
Contributor

bill3tt commented Jul 27, 2021

@Hangzhi

Since you are not modifying the e2e tests we can safely conclude that failed due to a transient flake. You can trigger a re-test with an empty commit git commit --allow-empty -m 'retest'.

If you inspect the output of the failing test it shows you why the linter is failing. If you inspect the makefile that is running the tests, you will find the binary we run (mdox) which you can run locally to fix the issues. The command will be something like mdox fmt -l --links.validate.config-file=./.mdox.validate.yaml docs/proposals/20201019-prometheus-rules-in-observatorium-api.md

Signed-off-by: Hangzhi <[email protected]>
@Hangzhi
Copy link
Contributor Author

Hangzhi commented Jul 28, 2021

@ianbillett Thank you for your very helpful information! I finally got the error info in detail with mdox fmt -l docs/proposals-accepted/202107-protobuf-openapi-httpapi.md.

Copy link
Member

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Amazing work!

Let's merge it, it has all details we want, problem and goals outlined well 💪🏽

On our 1:2 we acknowledged that this proposal has some risk - there are things we need to experiment with. This is fine though -we can iterate on it. Edit the "HOW" when we find new things or reject it at then end if needed. But current version shows the latest direction.

@bwplotka bwplotka merged commit b7735a6 into thanos-io:main Jul 29, 2021
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.

4 participants