Skip to content
This repository was archived by the owner on Sep 19, 2019. It is now read-only.

Self assigned request ID#193

Open
SteveHNH wants to merge 5 commits intomasterfrom
self_assigned_payload_id
Open

Self assigned request ID#193
SteveHNH wants to merge 5 commits intomasterfrom
self_assigned_payload_id

Conversation

@SteveHNH
Copy link
Copy Markdown
Collaborator

In the event that local testing is being done or 3scale doesn't assign an ID for some reason, we self-generate one. These are distinguished by having leading 0's to show that it's been self generated.

This stems from a conversation in https://projects.engineering.redhat.com/browse/RHCLOUD-516

SteveHNH added 4 commits May 14, 2019 14:13
If 3scale doesn't provide a request_id, or testing is done locally, we
generate a request_id. We also only reply with the proper header
containing that ID if it matches the leading zeroes format we have. The
chances of uuid4 generating a uuid that matches this check is super low
@SteveHNH SteveHNH requested review from Jason-RH and dehort May 17, 2019 18:45
payload_id key has been changed
Comment thread app.py
"""
mnm.uploads_total.inc()
self.request_id = self.request.headers.get('x-rh-insights-request-id', uuid.uuid4().hex)
self.request_id = self.request.headers.get('x-rh-insights-request-id', "00000" + uuid.uuid4().hex)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't see anything technically wrong with this. However, I do have a couple of suggestions:

  1. You might consider making the prefix a "constant" ...something like "GENERATED_REQUEST_ID_PREFIX". You could then use this name in the code instead of the hardcoded string. I use constants/names because I have a tendency to "booger" up the strings by misspelling the words, missing a "0", etc.

  2. You might consider moving the request_id generation into a method:
    def generate_request_id():
    return GENERATED_REQUEST_ID_PREFIX + uuid.uuid4().hex

  3. You might consider moving the retrieval of the x-rh-insights-request-id to a method:
    def get_request_id(request):
    return request.headers.get("x-rh-insights-request-id", generate_request_id())

I try to use method names (instead of comments) to try to end up with self-documenting code (that's the theory at least :) ). The other nice thing that comes out of splitting the logic into more (smaller) methods is containment and with containment...you end up with code that is easier to move around (when you figure out it doesn't belong where its currently located) and code that is easier to unit test.

Comment thread app.py

self.filedata = body

if self.request_id[:5] == "00000":
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't see anything wrong with this code either.

The same suggestions apply. I would try to wrap the prefix comparison logic in a method. Basically I would try to make it more clear what the intentions of this code is.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants