Skip to content

encode/decode DeadlineExpiredException types #30

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

Merged
merged 11 commits into from
Feb 14, 2025

Conversation

bjlaub
Copy link
Contributor

@bjlaub bjlaub commented Feb 12, 2025

No description provided.

@changelog-app
Copy link

changelog-app bot commented Feb 12, 2025

Generate changelog in changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

add header for hinting at expiration reasons

Check the box to generate changelog(s)

  • Generate changelog entry

Comment on lines 48 to 50
public interface ResponseEncodingAdapter<RESPONSE> {
void setHeader(RESPONSE response, String headerName, String headerValue);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could control the status code here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cool, done

@bjlaub bjlaub changed the title add header for hinting at expiration reasons encode/decode DeadlineExpiredException types Feb 12, 2025
@bjlaub bjlaub marked this pull request as ready for review February 12, 2025 20:28
public interface ResponseEncodingAdapter<RESPONSE> {
void setHeader(RESPONSE response, String headerName, String headerValue);

void setStatus(RESPONSE response, int status);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

perhaps we should invert this and use the visitor style a la QosException

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to expand on that: reason being that in e.g. palantir/conjure-java#2454, we're leveraging the private ConjureExceptions#writeResponse which accepts an http status as a parameter, but also contains useful logic that we probably want to re-use involved in writing the response body.

instead of including a setStatus() method on the encoder, we could expose a basic method here:

public int httpStatusFor(DeadlineExpiredException exception) {
    if (exception instanceof DeadlineExpiredException.External) {
        return 400;
    } else if (exception instanceof DeadlineExpiredException.Internal) {
        return 500;
    }
    return 500;
}

thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think either way could work. I don't think we necessarily need to send a response at all (similarly to QosException), although I suppose an errorInstanceId might be nice to quickly find the failures propagation path back to clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to use the visitor thing. i don't love it... but i guess it works

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 think this is simpler: 8fbd209

@@ -31,6 +31,8 @@ private DeadlineExpiredException(String message) {
super(message);
}

public abstract int httpStatusCode();
Copy link
Contributor

Choose a reason for hiding this comment

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

Slight preference to put these into a helper method on Deadlines.java along the lines of int getHttpStatusCode(DeadlineExpiredException), that way the exceptions themselves aren't directly coupled to http.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

works for me, will fix

Comment on lines 44 to 52
public static int getHttpStatusCode(DeadlineExpiredException.External _exception) {
// external deadline expiration is considered a client error
return 400;
}

public static int getHttpStatusCode(DeadlineExpiredException.Internal _exception) {
// internal deadline expiration is considered a server error
return 500;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on merging this to public static int getHttpStatusCode(DeadlineExpiredException exception) { so we don't need to inspect the type to get the correct status code? Makes future additions a bit easier imo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, fixed: 7669548

Comment on lines 37 to 41
return reason.flatMap(s -> switch (s) {
case "external" -> Optional.of(DeadlineExpiredException.external());
case "internal" -> Optional.of(DeadlineExpiredException.internal());
default -> Optional.empty();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we check the status code for internal/external as well? Ideally we're as precise as possible, only producing DeadlineExpiredException.external when the response status is 400, and internal when the status is 500

}

public interface ResponseDecodingAdapter<RESPONSE> {
Optional<String> getFirstHeader(RESPONSE response, String headerName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on using @Nullable here instead of optional? I sort of wish we'd done that on the other adapter to avoid unnecessary optional allocation.

We could call it @Nullable String maybeFirstHeaer(RESPONSE response, String headerName), allowing us to add an equivalent method on the existing adapter in a follow-up

Comment on lines 78 to 81
@Deprecated
default Optional<String> getFirstHeader(RESPONSE response, String headerName) {
return Optional.empty();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this type is new in this PR, we can remove this method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah whoops

@bulldozer-bot bulldozer-bot bot merged commit e269f56 into develop Feb 14, 2025
5 checks passed
@bulldozer-bot bulldozer-bot bot deleted the blaub/exception-types-header branch February 14, 2025 16:40
@autorelease3
Copy link

autorelease3 bot commented Feb 14, 2025

Released 0.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants