-
Notifications
You must be signed in to change notification settings - Fork 21
Eng 3068 create node result qet routes for metrics and checks #1403
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
eunice-chan
wants to merge
7
commits into
main
Choose a base branch
from
eng-3068-create-nodemetricresultsgetquery-nodecheckresultsgetquery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d621468
Init impl of routes
eunice-chan 76877be
Merge branch 'main' of github.com:aqueducthq/aqueduct into eng-3068-c…
eunice-chan 17dedcb
Routes done
eunice-chan 8c6dbf8
Routes work
eunice-chan 47e6755
Uncomment
eunice-chan 90a5db4
Golang lint
eunice-chan 92e1e42
UI Lint
eunice-chan 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
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
147 changes: 147 additions & 0 deletions
147
src/golang/cmd/server/handler/v2/node_check_results_get.go
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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| package v2 | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| "github.com/aqueducthq/aqueduct/cmd/server/handler" | ||
| "github.com/aqueducthq/aqueduct/lib/database" | ||
| "github.com/aqueducthq/aqueduct/lib/models" | ||
| "github.com/aqueducthq/aqueduct/lib/models/shared" | ||
| "github.com/aqueducthq/aqueduct/lib/models/views" | ||
| "github.com/aqueducthq/aqueduct/lib/repos" | ||
| "github.com/aqueducthq/aqueduct/lib/response" | ||
| "github.com/aqueducthq/aqueduct/lib/storage" | ||
| "github.com/dropbox/godropbox/errors" | ||
| "github.com/google/uuid" | ||
| ) | ||
|
|
||
| // This file should map directly to | ||
| // src/ui/common/src/handlers/v2/NodeCheckResultsGet.tsx | ||
| // | ||
| // Returns all downstream artifact results | ||
| // Route: /api/v2/workflow/{workflowID}/dag/{dagID}/node/check/{nodeID}/results | ||
| // Method: GET | ||
| // Params: | ||
| // `workflowID`: ID for `workflow` object | ||
| // `dagID`: ID for `workflow_dag` object | ||
| // `nodeID`: ID for operator object | ||
| // Request: | ||
| // Headers: | ||
| // `api-key`: user's API Key | ||
| // Response: | ||
| // Body: | ||
| // `[]response.OperatorWithArtifactResultNode` | ||
|
|
||
| type NodeCheckResultsGetHandler struct { | ||
| nodeGetHandler | ||
| handler.GetHandler | ||
|
|
||
| Database database.Database | ||
|
|
||
| WorkflowRepo repos.Workflow | ||
| DAGRepo repos.DAG | ||
| OperatorRepo repos.Operator | ||
| OperatorResultRepo repos.OperatorResult | ||
| ArtifactRepo repos.Artifact | ||
| ArtifactResultRepo repos.ArtifactResult | ||
| } | ||
|
|
||
| func (*NodeCheckResultsGetHandler) Name() string { | ||
| return "NodeCheckResultsGet" | ||
| } | ||
|
|
||
| func (h *NodeCheckResultsGetHandler) Prepare(r *http.Request) (interface{}, int, error) { | ||
| return h.nodeGetHandler.Prepare(r) | ||
| } | ||
|
|
||
| func (h *NodeCheckResultsGetHandler) Perform(ctx context.Context, interfaceArgs interface{}) (interface{}, int, error) { | ||
| args := interfaceArgs.(*nodeGetArgs) | ||
|
|
||
| artfID := args.nodeID | ||
| wfID := args.workflowID | ||
|
|
||
| emptyResponse := []response.OperatorWithArtifactResultNode{} | ||
|
|
||
| dbOperatorWithArtifactNodes, err := h.OperatorRepo.GetOperatorWithArtifactByArtifactIdNodeBatch(ctx, []uuid.UUID{artfID}, h.Database) | ||
| if err != nil { | ||
| return nil, http.StatusInternalServerError, errors.Wrap(err, "Unexpected error reading check node.") | ||
| } | ||
| dbOperatorWithArtifactNode := views.OperatorWithArtifactNode{} | ||
| if len(dbOperatorWithArtifactNodes) == 0 { | ||
| return emptyResponse, http.StatusOK, nil | ||
| } else { | ||
| dbOperatorWithArtifactNode = dbOperatorWithArtifactNodes[0] | ||
| } | ||
|
|
||
| results, err := h.OperatorResultRepo.GetOperatorWithArtifactResultNodesByOperatorNameAndWorkflow(ctx, dbOperatorWithArtifactNode.Name, wfID, h.Database) | ||
| if err != nil { | ||
| return emptyResponse, http.StatusInternalServerError, errors.Wrap(err, "Unable to retrieve check results.") | ||
| } | ||
|
|
||
| if len(results) == 0 { | ||
| return emptyResponse, http.StatusOK, nil | ||
| } | ||
|
|
||
| resultArtifactIds := make([]uuid.UUID, 0, len(results)) | ||
| for _, result := range results { | ||
| resultArtifactIds = append(resultArtifactIds, result.ArtifactResultID) | ||
|
eunice-chan marked this conversation as resolved.
|
||
| } | ||
|
|
||
| artfResultToDAG, err := h.DAGRepo.GetByArtifactResultBatch(ctx, resultArtifactIds, h.Database) | ||
| if err != nil { | ||
| return emptyResponse, http.StatusInternalServerError, errors.Wrap(err, "Unable to retrieve workflow dags.") | ||
| } | ||
|
|
||
| // maps from db dag Ids | ||
| dbDagByDagId := make(map[uuid.UUID]models.DAG, len(artfResultToDAG)) | ||
| nodeResultByDagId := make(map[uuid.UUID][]views.OperatorWithArtifactResultNode, len(artfResultToDAG)) | ||
| for _, nodeResult := range results { | ||
| if dbDag, ok := artfResultToDAG[nodeResult.ArtifactResultID]; ok { | ||
| if _, okDagsMap := dbDagByDagId[dbDag.ID]; !okDagsMap { | ||
| dbDagByDagId[dbDag.ID] = dbDag | ||
| } | ||
|
|
||
| nodeResultByDagId[dbDag.ID] = append(nodeResultByDagId[dbDag.ID], nodeResult) | ||
| } else { | ||
| return emptyResponse, http.StatusInternalServerError, errors.Newf("Error retrieving dag associated with artifact result %s", nodeResult.ArtifactResultID) | ||
| } | ||
| } | ||
|
|
||
| responses := make([]response.OperatorWithArtifactResultNode, 0, len(results)) | ||
| for dbDagId, nodeResults := range nodeResultByDagId { | ||
|
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. Try to consolidate these repeating parts. We can file a task if the solution is not immediately clear |
||
| if dag, ok := dbDagByDagId[dbDagId]; ok { | ||
| storageObj := storage.NewStorage(&dag.StorageConfig) | ||
| if err != nil { | ||
| return emptyResponse, http.StatusInternalServerError, errors.New("Error retrieving artifact contents.") | ||
| } | ||
|
|
||
| for _, nodeResult := range nodeResults { | ||
| var contentPtr *string = nil | ||
| if !nodeResult.ArtifactResultExecState.IsNull && | ||
| (nodeResult.ArtifactResultExecState.ExecutionState.Status == shared.FailedExecutionStatus || | ||
| nodeResult.ArtifactResultExecState.ExecutionState.Status == shared.SucceededExecutionStatus) { | ||
| exists := storageObj.Exists(ctx, nodeResult.ContentPath) | ||
| if exists { | ||
| contentBytes, err := storageObj.Get(ctx, nodeResult.ContentPath) | ||
| if err != nil { | ||
| return emptyResponse, http.StatusInternalServerError, errors.Wrap(err, fmt.Sprintf("Error retrieving artifact content for result %s", nodeResult.ArtifactID)) | ||
| } | ||
|
|
||
| contentStr := string(contentBytes) | ||
| contentPtr = &contentStr | ||
| } | ||
| } | ||
|
|
||
| responses = append(responses, *response.NewOperatorWithArtifactResultNodeFromDBObject( | ||
| &nodeResult, contentPtr, | ||
| )) | ||
| } | ||
| } else { | ||
| return emptyResponse, http.StatusInternalServerError, errors.Newf("Error retrieving dag %s", dbDagId) | ||
| } | ||
| } | ||
|
|
||
| return responses, http.StatusOK, nil | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.