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

feat: add sessionID HTTP Header to the Docker client setup #570

Merged
merged 5 commits into from Oct 18, 2022

Conversation

mdelapenya
Copy link
Collaborator

@mdelapenya mdelapenya commented Oct 18, 2022

What does this PR do?

It initialises the sessionID of the containers just once, as in the past it was created per-container, and this is not the expected behavior.

For that, we have created a global sessionID variable that is protected by sync.Once, therefore it's called just once.

This variable is used in the library with a singleton method, which is called from everywhere that a new UUID was required by a container. Therefore, all containers will share the same sessionID during a test execution/session.

Besides that, we detected a minor change in how the reaper was declaring its sessionID, using a variable with a wider scope: we have moved that sessionID variable to its own scope.

Finally, we are adding an HTTP header to the setup of the Docker client, which will allow improving tracing and other operations.

Why is it important

Better observability at the Docker API level, as we are instrumenting the HTTP requests.

With these changes we are also decoupling bit-by-bit the existing codebase: before them, the calculation of the sessionID happened everytime a container/network was created. Now, it happens just once per test execution.

Related issues

@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Oct 18, 2022
@mdelapenya mdelapenya self-assigned this Oct 18, 2022
@mdelapenya mdelapenya requested a review from a team as a code owner October 18, 2022 11:19
@@ -72,6 +71,11 @@ func NewReaper(ctx context.Context, sessionID string, provider ReaperProvider, r
WaitingFor: wait.ForListeningPort(listeningPort),
}

// include reaper-specific labels to the reaper container
for k, v := range reaper.Labels() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@codecov
Copy link

codecov bot commented Oct 18, 2022

Codecov Report

Merging #570 (0456937) into main (d9bb488) will decrease coverage by 34.82%.
The diff coverage is 88.88%.

@@             Coverage Diff             @@
##             main     #570       +/-   ##
===========================================
- Coverage   69.25%   34.43%   -34.83%     
===========================================
  Files          22       13        -9     
  Lines        2202     1757      -445     
===========================================
- Hits         1525      605      -920     
- Misses        539     1056      +517     
+ Partials      138       96       -42     
Impacted Files Coverage Δ
docker.go 41.15% <77.77%> (-30.98%) ⬇️
reaper.go 75.43% <100.00%> (-8.35%) ⬇️
session.go 100.00% <100.00%> (ø)
parallel.go 0.00% <0.00%> (-97.11%) ⬇️
compose.go 0.00% <0.00%> (-74.05%) ⬇️
file.go 0.00% <0.00%> (-52.95%) ⬇️
logger.go 50.00% <0.00%> (-50.00%) ⬇️
mounts.go 50.00% <0.00%> (-50.00%) ⬇️
docker_mounts.go 46.34% <0.00%> (-48.79%) ⬇️
generic.go 30.55% <0.00%> (-44.45%) ⬇️
... and 13 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@kiview kiview left a comment

Choose a reason for hiding this comment

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

Makes semantically sense from my testcontainers-java point of view 👍 (can't comment on any Go specifics).

Copy link
Contributor

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

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

Makes semantically sense from my testcontainers-java point of view 👍 (can't comment on any Go specifics).

Same for .NET.

@mdelapenya mdelapenya merged commit db41dd1 into testcontainers:main Oct 18, 2022
mdelapenya referenced this pull request in mdelapenya/testcontainers-go Oct 18, 2022
* chore: create network's session ID for reaper, only

* chore: include reaper-specific labels to the reaper container

* feat: initialise sessionID just once

* chore: do not expose the sessionID function

* fix: update reaper tests
mdelapenya referenced this pull request in mdelapenya/testcontainers-go Oct 18, 2022
* main:
  feat: add sessionID HTTP Header to the Docker client setup (#570)
mdelapenya added a commit that referenced this pull request Oct 19, 2022
* fix: pass docker context key when reusing a container

* feat: add sessionID HTTP Header to the Docker client setup (#570)

* chore: create network's session ID for reaper, only

* chore: include reaper-specific labels to the reaper container

* feat: initialise sessionID just once

* chore: do not expose the sessionID function

* fix: update reaper tests

* chore: add unit tests for extracting the docker host for reaper

* chore: add tests for the docker host when it's passed as part of the context
@mdelapenya mdelapenya deleted the http-headers branch October 31, 2022 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants