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

Experiment with extra check for an uploaded file #341

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

whytheplatypus
Copy link
Collaborator

This double checks an uploaded file's existence in the pre-finish hook, which is called after a file is uploaded but before a response to a client.

@whytheplatypus whytheplatypus marked this pull request as ready for review May 7, 2024 17:33
@@ -57,6 +59,9 @@ func Serve(appConfig appconfig.AppConfig) (http.Handler, error) {
logger.Error("error configuring tusd handler: ", "error", err)
return nil, err
}
if h, ok := hookHandler.(*prebuilthooks.PrebuiltHook); ok {
h.Register(tusHooks.HookPreFinish, uploadInfoHandler.Hook)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the post finish hook?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://tus.github.io/tusd/advanced-topics/hooks/#list-of-available-hooks pre-finish should fire after the upload is done but before responding to the client.

Copy link

Choose a reason for hiding this comment

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

Alternatively, you can also use the PreFinishResponseCallback from Config, which is the basis for the pre-finish hook and therefore provides the same capabilities. This could be a useful alternative if this change is the only reason why you start adding hooks.

@whytheplatypus whytheplatypus marked this pull request as draft May 7, 2024 18:30
ctx := event.Context

var fileInfo map[string]any
for i := 0; i < 5; i++ {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make this configurable

if fileInfo != nil {
break
}
time.Sleep(1 * time.Second)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make this configurable

var err error
fileInfo, err = ih.inspecter.InspectInfoFile(ctx, id)
if err != nil {
logger.Info("Failed to validate manifest file after upload", "id", id, "error", err, "manifest", fileInfo)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Include the number of attempts in all logs


if uploadedFileInfo == nil {
logger.Error("Failed to validate upload file", "id", id, "manifest", fileInfo, "upload", uploadedFileInfo)
return resp, errors.New("failed to find the uploaded file")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

normalize errors and include the upload id

time.Sleep(1 * time.Second)
}
var uploadedFileInfo map[string]any
for i := 0; i < 5; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

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

why iterate limit to 5?

Copy link
Contributor

Choose a reason for hiding this comment

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

could create a variable called maxRetries to represent the iteration limit


"github.com/cdcgov/data-exchange-upload/upload-server/internal/appconfig"
"github.com/cdcgov/data-exchange-upload/upload-server/internal/storeaz"
"github.com/cdcgov/data-exchange-upload/upload-server/pkg/azureinspector"
"github.com/cdcgov/data-exchange-upload/upload-server/pkg/fileinspector"
"github.com/cdcgov/data-exchange-upload/upload-server/pkg/info"
"github.com/tus/tusd/v2/pkg/handler"
"github.com/tus/tusd/v2/pkg/hooks"
)

type UploadInspecter interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this UploadInspector or UploadInspecter? in info.go, you call a method called createInspector()`

Copy link

sonarcloud bot commented May 24, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@whytheplatypus
Copy link
Collaborator Author

whytheplatypus commented May 24, 2024

quick benchmark shows no meaningful change in performance with or without verification.

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.

5 participants