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

fix(adserver): adserver returns cloudevents compatible response #5348

Conversation

michaelcheah
Copy link
Contributor

What this PR does / why we need it:

The adserver is meant to be deployed as a knative serving service. However, it is currently not setting the appropriate headers in its http response in the POST handler for the response to be considered a CloudEvent message. As can be seen by the spec, the following attributes must be present in the http message:

  • id
  • source
  • specversion
  • type

Previously, none of these attributes were set in the response (though they were set when the message was forwarded to the replyUrl)

This PR does the following:

  1. Fixes some type checks
  2. Adds extra assertions in the test_server.py file to check that responses are CE compatible
  3. Refactors the server's POST handler to return CE messages

@@ -21,7 +21,7 @@
SELDON_PREDICTOR_ID = DEFAULT_LABELS["predictor_name"]


def _load_class_module(module_path: str) -> str:
def _load_class_module(module_path: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? It still seems to return str, or not?

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 actually returns a Module. It was raising type hint warnings because it's used like so in L77-79

            # Load from locally available models
            MetricsClass = _load_class_module(self.storage_uri)
            self.model = MetricsClass()

Copy link
Contributor

Choose a reason for hiding this comment

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

so potentially -> "Module" (or other appropriate way to annotate the return type) could be good?

Copy link
Contributor

Choose a reason for hiding this comment

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

probably you'd need to import appropriate type

Copy link
Contributor

@majolo majolo left a comment

Choose a reason for hiding this comment

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

Probably best for another approval from someone with more up-to-date production python knowledge, but logic looks good to me.

Good job on getting this resolved properly!

@RafalSkolasinski
Copy link
Contributor

@michaelcheah please mark as Ready for review - I will hold my full review until then

@michaelcheah michaelcheah marked this pull request as ready for review February 19, 2024 15:49
Copy link
Contributor

@RafalSkolasinski RafalSkolasinski left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@michaelcheah michaelcheah merged commit 1f32089 into SeldonIO:master Feb 19, 2024
12 of 13 checks passed
@michaelcheah michaelcheah deleted the adserver-returns-cloudevents-compatible-response branch February 19, 2024 17:03
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.

3 participants