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

Implemented Artifactory upload and download handling #30

Open
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

eeasaa01
Copy link

@eeasaa01 eeasaa01 commented Nov 5, 2024

Implemented Artifactory Cache Integration

Changes

  • Added GRABIT_ARTIFACTORY_TOKEN support
  • Implemented cache download priority
  • Added fallback to source URLs
  • Added integrity validation
  • Added unit tests for cache functionality
  • Added integration tests
  • Fixed logging levels
  • Added proper error handling

Testing Done

  • Added TestGrabitRequirements for comprehensive testing
  • Tested token validation
  • Tested cache download and fallback
  • Tested NO_CACHE_UPLOAD
  • Tested error handling
  • All tests passing

Changes Made Based on Feedback

  • Fixed authentication error handling
  • Adjusted log levels for cache operations
  • Improved error messages
  • Added proper validation at each step
  • Added comprehensive test coverage

Checklist

  • I have read the contributing guidelines
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

Copy link
Contributor

@jsquyres jsquyres left a comment

Choose a reason for hiding this comment

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

There appears to be quite a bit of functionality and many changes that are not directly related to the Artifactory / caching functionality, which makes this PR a bit hard to read and review.

Also, can we get the writeup of what we decided would be the first cut of this functionality? Without that, @rabadin can't properly evaluate this code.

I assume that you notice that the CI tests are failing, too. You'll want to make test before you push again and make sure everything passes.

Finally, let's talk in the next meeting about how to add some unit tests for this functionality.

cmd/add.go Outdated Show resolved Hide resolved
cmd/add.go Outdated Show resolved Hide resolved
cmd/download.go Outdated Show resolved Hide resolved
cmd/download.go Outdated Show resolved Hide resolved
cmd/download.go Outdated Show resolved Hide resolved
internal/lock.go Show resolved Hide resolved
internal/lock.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
cmd/add.go Outdated Show resolved Hide resolved
cmd/add.go Outdated Show resolved Hide resolved
cmd/add.go Outdated Show resolved Hide resolved
cmd/add.go Outdated Show resolved Hide resolved
@jsquyres
Copy link
Contributor

jsquyres commented Nov 7, 2024

Note that this PR now has a (simple) conflict that has to be fixed. Github won't run the CI on a PR that has conflicts, which is why there's currently no CI results here.

eeasaa01 and others added 10 commits November 8, 2024 00:14
- Added TestGrabitRequirements
- Tested token validation
- Tested cache download and fallback
- Tested NO_CACHE_UPLOAD
- Tested error handling
- All tests passing
Implemented Artifactory upload and download handling

- Added GRABIT_ARTIFACTORY_TOKEN support
- Implemented cache download priority
- Added fallback to source URL
- Added validation at each step
- Improved error handling and logging
- Integrated cache upload functionality#
pick 0ea343f Implemented requested changes and added tests for Artifactory integration

pick 082c98b Added comprehensive tests for Artifactory cache functionality
- Added TestGrabitRequirements
- Tested token validation
- Tested cache download and fallback
- Tested NO_CACHE_UPLOAD
- Tested error handling
- All tests passing
Copy link
Contributor

@jsquyres jsquyres left a comment

Choose a reason for hiding this comment

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

Need to remove the a640.... binary.

FWIW: Using git add -a or git commit -a is dangerous. It is much safer to git add ...list of files... or git add -p to select precisely which things you want to add to the staging area.

.gitignore Outdated Show resolved Hide resolved
cmd/add.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
- Removed binary file a640986bc2
- Updated .gitignore to exclude binaries and artifacts
- Modified cmd/add.go to properly handle cache
- Updated internal/resource.go for cache functionality
- Improved error handling per review
- Modified function to take token as parameter
- Removed duplicate os.Getenv call
- Improved error messages
- Fixed as per code review feedback
- Changed NO_CACHE_UPLOAD to GRABIT_NO_CACHE_UPLOAD
- Following naming convention for environment variables
- Addressing code review feedback
- Fix empty if block in downloadFromSource
- Update variable naming for consistency
- Move algorithm extraction
- Improve code organization
- Replace http.NewRequest with requests library
- Remove unnecessary comment
- Keep same functionality with safer implementation
- Follow code review feedback
internal/resource.go Outdated Show resolved Hide resolved
internal/hash.go Outdated Show resolved Hide resolved
internal/lock.go Outdated
}
defer file.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it yes. A small one since this would be GCed but still.

@eeasaa01 eeasaa01 marked this pull request as draft November 13, 2024 13:34
@eeasaa01 eeasaa01 marked this pull request as ready for review November 18, 2024 21:00
@jsquyres
Copy link
Contributor

It looks like there were some bad merges that were not fixed properly before committing. For example, I see a full Open MPI tarball added in 4033f12. Word to the wise: you should avoid using git add -a or git commit -a. It is far to easy to commit files that you do not intend.

Additionally, make test fails to compile the tests (it looks like there's some git conflict markers that were left in the source files). This is one reason that the CI is failing. In general, you should probably ensure that grabit builds properly and the tests are passing before pushing up to github.

internal/lock.go Show resolved Hide resolved
internal/resource_test.go Outdated Show resolved Hide resolved
internal/resource_test.go Outdated Show resolved Hide resolved
internal/resource.go Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
internal/resource.go Outdated Show resolved Hide resolved
internal/lock_test.go Outdated Show resolved Hide resolved
internal/artifactory_cache_test.go Outdated Show resolved Hide resolved
grsbit Outdated Show resolved Hide resolved
internal/lock.go Outdated Show resolved Hide resolved
artifactoryURL := fmt.Sprintf("%s/%s", cacheURL, hexHash)

// Create upload request
req, err := http.NewRequest("PUT", artifactoryURL, bytes.NewReader(fileContent))
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, let's use github.com/carlmjohnson/requests for non-test http interactions, like the rest of the code does.

}
}
l.conf.Resource = newStatements
}

func deleteCache(url, token string) error {
req, err := http.NewRequest("DELETE", url, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same remark here, let use github.com/carlmjohnson/requests for http interactions.

internal/lock.go Outdated Show resolved Hide resolved
@rabadin
Copy link
Contributor

rabadin commented Nov 27, 2024

@amdurh05 Also, you have a random 11M binary file in here.

@@ -112,9 +112,9 @@ func TestRunDownloadFailsIntegrityTest(t *testing.T) {
content := `abcdef`
port := test.TestHttpHandler(content, t)
testfilepath := test.TmpFile(t, fmt.Sprintf(`
[[Resource]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's revert these whitespace changes. There's no need for these changes for the Artifactory functionality.

Copy link
Author

Choose a reason for hiding this comment

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

We did not make any changes in this part of the file. I believe these whitespace modifications were introduced by Mr. Raphael in a prior commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

This file is poorly named, but let's not rename it as part of this PR -- let's rename it in a separate PR.

func TestDownloadWithArtifactoryCache(t *testing.T) {
t.Run("NO_CACHE_UPLOAD", func(t *testing.T) {
// Turn on NO_CACHE_UPLOAD setting
os.Setenv("NO_CACHE_UPLOAD", "1")
Copy link
Contributor

@rabadin rabadin Nov 27, 2024

Choose a reason for hiding this comment

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

Use https://pkg.go.dev/testing#B.Setenv instead. This guarantees that it gets restored after the test runs.

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.

4 participants