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

Inspections #81

Merged
merged 90 commits into from
Aug 11, 2023
Merged

Inspections #81

merged 90 commits into from
Aug 11, 2023

Conversation

timmarkhuff
Copy link
Contributor

@timmarkhuff timmarkhuff commented Aug 2, 2023

This PR adds several methods to Groundlight that are required for the RPC Server/URCap. They are intended to be released as undocumented features and only used to support the RPC Server/URCap on the SDK (for now at least).

Since the required functionality for these methods is not available in image_queries_api, they use the internal API directly.

New methods include:
start_inspection
update_inspection_metadata
stop_inspection
update_detector_confidence_threshold

There was also some logic added to submit_image_query related to inspections: if an image query is submitted with no inspection_id, the query will be submitted through image_queries_api (as it has been previously), however if submit_image_query is called with an inspection_id, we use the private API client instead.

@timmarkhuff timmarkhuff marked this pull request as ready for review August 10, 2023 21:36
pyproject.toml Outdated
@@ -9,7 +9,7 @@ packages = [
{include = "**/*.py", from = "src"},
]
readme = "README.md"
version = "0.10.1"
version = "0.10.2"
Copy link
Member

Choose a reason for hiding this comment

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

I'd say we should call this 0.11 - not because it's backwards incompatible, but because if somebody asks "what version of the SDK do I need to use UR Cap?" it's a bit nicer to say "0.11" than "you need at least "0.10.2".

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 good with 0.11.0

I had originally recommended 0.10.2 to Tim because I was hoping to include the change to move inspection_id into the regular public API before bumping to 0.11.0. But that change will technically be backwards-compatible (and kinda a hidden implementation detail), so maybe you're right that we should bump to 0.11.0.

@mjvogelsong mjvogelsong self-requested a review August 10, 2023 22:19
Copy link
Contributor

@mjvogelsong mjvogelsong 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! Just a couple small changes requested, and then it should be good to go.

pyproject.toml Outdated
@@ -9,7 +9,7 @@ packages = [
{include = "**/*.py", from = "src"},
]
readme = "README.md"
version = "0.10.1"
version = "0.10.2"
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 good with 0.11.0

I had originally recommended 0.10.2 to Tim because I was hoping to include the change to move inspection_id into the regular public API before bumping to 0.11.0. But that change will technically be backwards-compatible (and kinda a hidden implementation detail), so maybe you're right that we should bump to 0.11.0.

Comment on lines 193 to 201
detector_id = detector.id if isinstance(detector, Detector) else detector

# Convert from Detector to detector_id if necessary
if isinstance(detector, Detector):
detector_id = detector.id
else:
detector_id = detector
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is equivalent to the one-liner, and I feel like the previous version is more concise -- is there a reason you wanted to break it out like this?

Comment on lines +242 to +244
# Convert from image_query_id to ImageQuery if needed.
if isinstance(image_query, str):
image_query = self.get_image_query(image_query)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we've added this, then we should update the typing above to:

image_query: Union[ImageQuery, str],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 244 to 258
url = (
f"{self.configuration.host}/posichecks"
f"?inspection_id={inspection_id}"
f"&predictor_id={detector_id}"
f"&patience_time={patience_time}"
)

# In the API, 'send_notification' is used to control human_review escalation. This will eventually
# be deprecated, but for now we need to support it in the following manner:
if human_review == "ALWAYS":
url += "&send_notification=True"
elif human_review == "NEVER":
url += "&send_notification=False"
else:
pass # append nothing to the URL, allow "DEFAULT" behavior
Copy link
Contributor

Choose a reason for hiding this comment

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

For the query parameters, I think we can use a dict, and feed it into requests.request(..., params=params). That way, we don't have to manage the ? and & in the URL, so it's a little cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 266 to 270
logger.info(response)
raise InternalApiError(
status=response.status_code,
reason=f"Error submitting image query with inspection ID {inspection_id} on detector {detector_id}",
)
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 we should show the response through the InternalApiError. Let's make this consistent throughout -- please add http_resp=response in the different methods below, as well.

Suggested change
logger.info(response)
raise InternalApiError(
status=response.status_code,
reason=f"Error submitting image query with inspection ID {inspection_id} on detector {detector_id}",
)
raise InternalApiError(
status=response.status_code,
reason=f"Error submitting image query with inspection ID {inspection_id} on detector {detector_id}",
http_resp=response,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


# Closing an inspection generates a new inspection PDF. Therefore, if the inspection
# is already closed, just return "COMPLETE" to avoid unnecessarily generating a new PDF.
response = requests.request("GET", url, headers=headers)
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 we want an is_ok() check 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.

done

@mjvogelsong mjvogelsong self-requested a review August 11, 2023 18:38
Copy link
Contributor

@mjvogelsong mjvogelsong left a comment

Choose a reason for hiding this comment

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

Great! Thanks for the comprehensive tests, as well.

response = requests.request("POST", url, headers=headers, params=params, data=body.read())

if not is_ok(response.status_code):
logger.info(response)
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 you can delete this line, now that response is in the error.

@timmarkhuff timmarkhuff merged commit 172d24b into main Aug 11, 2023
7 checks passed
@timmarkhuff timmarkhuff deleted the inspections branch August 11, 2023 18:44
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