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

perf(docker): Set cache data id, missing from un-grooving code #3961

Merged
merged 10 commits into from
Aug 22, 2019

Conversation

german-muzquiz
Copy link
Contributor

Changes of #3926 and #3942 (both reverted) adding the following:

  • Explicitly set id field of DefaultCacheDataBuilder and include it in tests.

This was previously set by groovy code implicitly rather than explicitly, by means of this code:

cachedTags[tagKey].with {
    attributes.name = "${repository}:${tag}".toString()
    attributes.account = accountName
    attributes.digest = digest
    attributes.date = creationDate
}

cachedTags was this MapWithDefault implementation:

[:].withDefault { String id -> new DefaultCacheDataBuilder(id: id) }

Above code first tried to fetch an entry from the map with key tagKey, and that caused the map to create and return a new instance of DefaultCacheDataBuilder automatically, with its id field set to the value of tagKey. When the code was ungroovied, id was missing to be set and cache entries were not properly saved, causing Igor to never find a new docker image.

german-muzquiz and others added 3 commits August 19, 2019 08:16
…pinnaker#3942)

* perf(docker): Use parallel streams for caching docker images

* chore(docker): Using java syntax for map updates

* perf(docker): Only parallelize loop of tags

* chore(docker): Use ConcurrentMap instead of ConcurrentHashMap

* perf(docker): Fix for ConcurrentHashMap cast error. Added unit tests

* perf(docker): Use parallel streams for caching docker images

(cherry picked from commit 011da56)
@german-muzquiz
Copy link
Contributor Author

@ezimanyi

@mrampton
Copy link
Contributor

Hi @ezimanyi -- this PR addresses the issue that was causing the previous PR to fail in our integration testing. It has been successfully tested in our environment and additional test coverage was added to ensure that the cache entry is stored with the correct key.

cacheResult.cacheResults.get("taggedImage").size() == total
cacheResult.cacheResults.get("imageId").size() == total
for (def i = 0; i < total; i++) {
cacheResult.cacheResults.get("taggedImage")[i].getId() != ""
Copy link
Contributor

Choose a reason for hiding this comment

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

It would probably make sense to ensure this is set to the expected value, not just that it's not the empty string. (This might involve stubbing the key generation logic if you want to keep it outside of the "unit" we're testing.)

name="repo-1"
tags=["tag-1", "tag-2"]
}
client.getDigest(*_) >> "123"
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be a bit more robust to return different digests for the different tags, and ensure the digests appear correctly in the output.

then:
cacheResult.cacheResults.get("taggedImage").size() == total
cacheResult.cacheResults.get("imageId").size() == total
for (def i = 0; i < total; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic in this for loop is somewhat hard to follow, and also looks like it's only testing that each returned tag is something we have in repoTags but not the reverse---that everything in repoTags is returned in the result.

I'd suggest being more explicit about the expected results, and then asserting that the set of expected results is the same as the set of actual results.

@german-muzquiz
Copy link
Contributor Author

@ezimanyi I improved tests validation by asserting on all expected exact values, they should be easier to read, and to troubleshoot failed tests on expected vs actual values.
I also added a few more tests to cover for exceptions, increasing class coverage to 75%

Copy link
Contributor

@ezimanyi ezimanyi left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@ezimanyi ezimanyi merged commit 3c4cffb into spinnaker:master Aug 22, 2019
@mrampton
Copy link
Contributor

@spinnakerbot cherry-pick 1.15

@mrampton mrampton deleted the fix/docker-trigger branch August 22, 2019 19:52
@mrampton mrampton restored the fix/docker-trigger branch August 22, 2019 19:53
spinnakerbot pushed a commit that referenced this pull request Aug 22, 2019
* perf(docker): Fix for ConcurrentHashMap cast error. Added unit tests (#3942)

* perf(docker): Use parallel streams for caching docker images

* chore(docker): Using java syntax for map updates

* perf(docker): Only parallelize loop of tags

* chore(docker): Use ConcurrentMap instead of ConcurrentHashMap

* perf(docker): Fix for ConcurrentHashMap cast error. Added unit tests

* perf(docker): Use parallel streams for caching docker images

(cherry picked from commit 011da56)

* perf(docker): Set cache data id, missing from un-grooving code

* perf(docker): Improved tests: explicit validations and extended coverage
@spinnakerbot
Copy link
Contributor

Cherry pick successful: #3974

@mrampton mrampton deleted the fix/docker-trigger branch August 22, 2019 19:59
@mrampton mrampton restored the fix/docker-trigger branch August 26, 2019 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants