Skip to content

Describe expected response times for responses #3063

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

Open
agardnerIT opened this issue Oct 25, 2022 · 11 comments
Open

Describe expected response times for responses #3063

agardnerIT opened this issue Oct 25, 2022 · 11 comments
Labels
http Supporting HTTP features and interactions OAI-scope

Comments

@agardnerIT
Copy link

I can describe expected return codes, response types and even expected responses via the spec: https://swagger.io/docs/specification/describing-responses/

What I feel is missing right now is the ability to document expected response times. As a developer, I know my endpoint should return in <100ms with a 201.

Is there a way to achieve this today (perhaps via some custom annotation?) or would this require a spec update. If so, how do I formally submit that as a request?

@rafalkrupinski
Copy link

That's an interesting idea.

I guess it would make sense to put it under either operation or server, you could use description or add a custom attribute e.g. x-timeout-ms.

The only problem is, there can always be a delay on the way, so if the operation, including the network transmission, takes 101ms, and client developer imposes that 100ms as a timeout, they lose the response.

The typical default timeout is 30sec for the reason that the internet doesn't guarantee response times.

@agardnerIT
Copy link
Author

agardnerIT commented Oct 25, 2022

My intention isn't to fail the response but more use it as a hint. Ie. when the request hits the API to the backend and back - that's the time I'm interested in hinting at.

Other actors can then infer expected behaviour. It would eliminate false callouts as I can see that actually, the dev intended it to take 5 seconds so no point in moaning that it is taking 3.

image

@agardnerIT
Copy link
Author

@rafalkrupinski how do I progress this? Can this be achieved now and if so, how? If not possible today, I'm more than happy to jump on calls / present this proposal. Just let me know where and when and I'll turn up.

Looking forward to PoCing htis if it is possible (I'm an OpenAPI newbie so a noob guide would be great for me :) )

@rafalkrupinski
Copy link

@agardnerIT
OAS allows arbitrary extension fields so I don't think you need to start a long process to change it for your particular needs.

How you support timeouts depends on your tooling.
If you use a code generator to create the client code, you can add an extension field and handle it in the generator (You say you don't want to fail the request, but I guess you'd add a warning).

If the client is coded by hand, you can either use an extension or simply the description field and let the client developer handle it in their code.

It's also a matter of how you create the schema. If it's generated from the server code, it also needs to support adding extension fields.

@darrelmiller
Copy link
Member

I would start by suggesting some x- extensions and let's see whether there is interest from a broader group of people. If it becomes popular we can considering incorporating the values into a future spec update.

@agardnerIT
Copy link
Author

Thanks. x-expected-response-time-ms

@AMorgaut
Copy link

AMorgaut commented Dec 5, 2022

I join this request

We're working on a framework that reads many information from a mandatory Open API specification file including:

  • request validation rules
  • success http status code
  • caching rules based on the defined response cache-control header

We also have mandatory response time requirements that we need to enforce in the specification as all routes don't have the same response time criticity based on business use cases.

I take this occasion to remind that this request also exists in fact in a still opened issue from 2016 ;-)

As no-standard field exists yes in OAS, we'll for sure start defining a vendor specific x-timeout, x-expected-response-time-ms, or x-max-response-time related field, but that will not help getting a better native support by existing open api tools

We expect such field, once standardized, to be interpreted & used by:

Moreover we could define rules in tools like Spectral to expect a 408 response from routes that define such timeout to detect such kind of potential issues before running service contact tests

@rafalkrupinski
Copy link

Does any of the open-source tools you've mentioned support timeout via a x- property so far?

@AMorgaut
Copy link

AMorgaut commented Dec 5, 2022

I still have to dig

The first I can mention is the timeoutInMillis property of the x-amazon-apigateway-integration vendor specific object property from the AWS API Gateway

On its side Apigee natively handles different types of timeouts in its products, but while you can publish Open API based services, their timeouts cannot be defined through that Open API specification. It only supports standard Open API fields

@agardnerIT
Copy link
Author

agardnerIT commented Dec 7, 2022

Costs Codes

Suggestions: x-cost and related x-cost-code

x-cost: "0.03"
x-cost-code: "USD"

Examples

Endpoint Evaluation

I have a system which calls a third party API. I am evaluating between two different third parties for this APIs. All the usual SLOs apply (response time etc.) but cost is also a major factor. If endpointA costs 3 "whatevers" per call and endpointB costs 30 "whatevers" per call - that's a major plus point for endpointA.

image

Direct cost tracking

If I have the above, my tooling can aggregate the header data and show:

You have spent 123.45USD over the last 24hrs with endpointA. This is x% of your budget.

Different Definitions of Cost

Cost of course can be monetary, but a "cost" could also indicate other quantities (like a carbon emissions costs).

@GabenGar
Copy link

GabenGar commented Jan 4, 2023

Doesn't this fall apart once proxy/reverse-proxy servers enter into the picture? They can add to a response time which can't be tracked by the application returning the header, and the client will not be able to tell apart a proxy/app response of 2/5 from 5/2.

@handrews handrews added OAI-scope http Supporting HTTP features and interactions labels Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Supporting HTTP features and interactions OAI-scope
Projects
None yet
Development

No branches or pull requests

6 participants