-
Notifications
You must be signed in to change notification settings - Fork 11
feat(stovepipe): request history api - by request URI #671
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
mnoah1
wants to merge
2
commits into
mnoah1/stovepipe-history-by-id
from
mnoah1/stovepipe-history-by-uri
+186
−12
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ import ( | |
| // RequestHistoryController handles retained request-history lookups. | ||
| type RequestHistoryController interface { | ||
| GetRequestHistoryByID(ctx context.Context, req entity.GetRequestHistoryByIDRequest) ([]entity.RequestLog, error) | ||
| GetRequestHistoryByURI(ctx context.Context, req entity.GetRequestHistoryByURIRequest) ([]entity.RequestHistory, error) | ||
| } | ||
|
|
||
| var _ RequestHistoryController = (*requestHistoryController)(nil) | ||
|
|
@@ -78,13 +79,65 @@ func (c *requestHistoryController) readHistoryByID(ctx context.Context, req enti | |
| return nil, fmt.Errorf("GetRequestHistoryByID failed to resolve storage for queue %q: %w", req.Queue, err) | ||
| } | ||
|
|
||
| logs, err := stores.GetRequestLogStore().List(ctx, req.ID) | ||
| logs, err := loadRequestLogs(ctx, stores.GetRequestLogStore(), req.ID, &RequestHistoryNotFoundError{RequestID: req.ID}) | ||
| if err != nil { | ||
| if storage.IsNotFound(err) { | ||
| return nil, errs.NewUserError(&RequestHistoryNotFoundError{RequestID: req.ID}) | ||
| } | ||
| return nil, fmt.Errorf("GetRequestHistoryByID failed to list request logs request_id=%s: %w", req.ID, err) | ||
| } | ||
|
|
||
| return logs, nil | ||
| } | ||
|
|
||
| // GetRequestHistoryByURI returns the retained history mapped to an exact commit URI. | ||
| func (c *requestHistoryController) GetRequestHistoryByURI(ctx context.Context, req entity.GetRequestHistoryByURIRequest) (histories []entity.RequestHistory, retErr error) { | ||
| op := metrics.Begin(c.metricsScope, "get_by_uri", metrics.StorageLatencyBuckets, metrics.TagsFromContext(ctx)...) | ||
| defer func() { op.Complete(retErr) }() | ||
|
|
||
| history, retErr := c.readHistoryByURI(ctx, req) | ||
| if retErr != nil { | ||
| return nil, retErr | ||
| } | ||
| c.logger.Debugw("request history retrieved by URI", | ||
| "uri", req.URI, | ||
| "request_id", history.RequestID, | ||
| "queue", req.Queue, | ||
| "event_count", len(history.Events), | ||
| ) | ||
| return []entity.RequestHistory{history}, nil | ||
| } | ||
|
|
||
| func (c *requestHistoryController) readHistoryByURI(ctx context.Context, req entity.GetRequestHistoryByURIRequest) (entity.RequestHistory, error) { | ||
| if err := validateHistoryIdentifier("queue", req.Queue); err != nil { | ||
| return entity.RequestHistory{}, fmt.Errorf("GetRequestHistoryByURI invalid queue: %w", err) | ||
| } | ||
| if err := validateHistoryIdentifier("URI", req.URI); err != nil { | ||
| return entity.RequestHistory{}, fmt.Errorf("GetRequestHistoryByURI invalid request: %w", err) | ||
| } | ||
|
|
||
| stores, err := c.stores.For(storage.Config{QueueName: req.Queue}) | ||
| if err != nil { | ||
| return entity.RequestHistory{}, fmt.Errorf("GetRequestHistoryByURI failed to resolve storage for queue %q: %w", req.Queue, err) | ||
| } | ||
|
|
||
| requestID, err := stores.GetRequestURIStore().GetIDByURI(ctx, req.URI) | ||
| if err != nil { | ||
| if storage.IsNotFound(err) { | ||
| return entity.RequestHistory{}, errs.NewUserError(&RequestHistoryNotFoundError{URI: req.URI}) | ||
| } | ||
| return entity.RequestHistory{}, fmt.Errorf("GetRequestHistoryByURI failed to resolve request URI %s: %w", req.URI, err) | ||
| } | ||
|
|
||
| logs, err := loadRequestLogs(ctx, stores.GetRequestLogStore(), requestID, &RequestHistoryNotFoundError{URI: req.URI}) | ||
| if err != nil { | ||
| return entity.RequestHistory{}, fmt.Errorf("GetRequestHistoryByURI failed to list request logs uri=%s request_id=%s: %w", req.URI, requestID, err) | ||
| } | ||
|
|
||
| return entity.RequestHistory{RequestID: requestID, Events: logs}, nil | ||
| } | ||
|
|
||
| func loadRequestLogs(ctx context.Context, store storage.RequestLogStore, requestID string, notFound *RequestHistoryNotFoundError) ([]entity.RequestLog, error) { | ||
| logs, err := store.List(ctx, requestID) | ||
| if storage.IsNotFound(err) { | ||
| return nil, errs.NewUserError(notFound) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is it a user error? If it finds requestID by URI, should the data down the pipe be consistent and if it is not, that's not a user's fault? |
||
| } | ||
| return logs, err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having expectations on how fields are set in the same struct could be error-prone. You may consider other designs: