open-telemetry / opentelemetry-dotnet

The OpenTelemetry .NET Client
https://opentelemetry.io
Apache License 2.0
3.18k stars 753 forks source link

Improve Integration Test by Generating TLS/mTLS Certificates via MSBuild #5818

Open sandy2008 opened 2 weeks ago

sandy2008 commented 2 weeks ago

Fixes #2009
Based on PR https://github.com/open-telemetry/opentelemetry-dotnet/pull/4731

Changes

This PR introduces an improvement in how integration tests handle TLS/mTLS certificates by generating them at build time via MSBuild. The generated certificates are stored in the build output directory.

Key Changes:

Merge requirement checklist

License Information

THIS SOFTWARE IS CONTRIBUTED SUBJECT TO THE TERMS OF THE APACHE LICENSE V.2.0. YOU MAY OBTAIN A COPY OF THE LICENSE AT https://github.com/open-telemetry/opentelemetry-python/blob/master/LICENSE.

THIS SOFTWARE IS LICENSED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY WARRANTY OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THIS SOFTWARE MAY BE REDISTRIBUTED TO OTHERS ONLY BY EFFECTIVELY USING THIS OR ANOTHER EQUIVALENT DISCLAIMER IN ADDITION TO ANY OTHER REQUIRED LICENSE TERMS.

codecov[bot] commented 2 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 86.21%. Comparing base (6250307) to head (f6c4b00). Report is 321 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5818/graphs/tree.svg?width=650&height=150&src=pr&token=vscyfvPfy5&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5818?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) ```diff @@ Coverage Diff @@ ## main #5818 +/- ## ========================================== + Coverage 83.38% 86.21% +2.83% ========================================== Files 297 257 -40 Lines 12531 11168 -1363 ========================================== - Hits 10449 9629 -820 + Misses 2082 1539 -543 ``` | [Flag](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5818/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5818/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `?` | | | [unittests-Project-Experimental](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5818/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `86.19% <ø> (?)` | | | [unittests-Project-Stable](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5818/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry) | `86.17% <ø> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry#carryforward-flags-in-the-pull-request-comment) to find out more. [see 223 files with indirect coverage changes](https://app.codecov.io/gh/open-telemetry/opentelemetry-dotnet/pull/5818/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-telemetry)
sandy2008 commented 2 weeks ago

@reyang Hi! Fixed accordingly.

sandy2008 commented 2 weeks ago

@reyang Do you know what's the next step to get it merged, so that we can work on the remaining PRs to support mTLS? 🥹

reyang commented 2 weeks ago

@reyang Do you know what's the next step to get it merged, so that we can work on the remaining PRs to support mTLS? 🥹

sandy2008 commented 2 weeks ago

@reyang @alanwest Please kindly review again!

alanwest commented 2 weeks ago

@sandy2008 try running the test locally. The CI does not pass.

sandy2008 commented 2 weeks ago

@sandy2008 try running the test locally. The CI does not pass.

Sorry sorry, I forgot to push one change..

sandy2008 commented 2 weeks ago

@alanwest Hmm, seems I need to give one fix, will fix it tmr.

sandy2008 commented 1 week ago

Sorry, I was little busy during the weekend, I will work on it again today.

sandy2008 commented 1 week ago

@alanwest Please review again, all fixed :)

alanwest commented 1 week ago

@sandy2008 The test is still failing.

The certs are not being written to the necessary directory

Screenshot 2024-09-20 at 2 25 49 PM

To validate that things will work, you can run this integration test locally in the same way the CI runs it

https://github.com/open-telemetry/opentelemetry-dotnet/blob/c1a1931319281197598d009ed531475e5a914de1/.github/workflows/ci.yml#L118

Be sure to run this command from the root of the repository:

docker compose --file=test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/docker-compose.yml --file=build/docker-compose.net8.0.yml --project-directory=. up --exit-code-from=tests --build
sandy2008 commented 3 days ago
```shell
docker compose --file=test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/docker-compose.yml --file=build/docker-compose.net8.0.yml --project-directory=. up --exit-code-from=tests --build

Hi, it seems that the tests are successfully locally, is it a way that I can trigger my own tests on cloud?

opentelemetry-dotnet-tests-1           | Test Run Successful.
opentelemetry-dotnet-tests-1           | Total tests: 26
opentelemetry-dotnet-tests-1           |      Passed: 26
opentelemetry-dotnet-tests-1           |  Total time: 1.0136 Minutes
opentelemetry-dotnet-tests-1 exited with code 0
Aborting on container exit...
[+] Stopping 2/0
 ✔ Container opentelemetry-dotnet-tests-1           Stopped                0.0s 
 ✔ Container opentelemetry-dotnet-otel-collector-1  Stopped                0.1
sandy2008 commented 3 days ago
```shell
docker compose --file=test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/IntegrationTest/docker-compose.yml --file=build/docker-compose.net8.0.yml --project-directory=. up --exit-code-from=tests --build

Hi, it seems that the tests are successfully locally, is it a way that I can trigger my own tests on cloud?

opentelemetry-dotnet-tests-1           | Test Run Successful.
opentelemetry-dotnet-tests-1           | Total tests: 26
opentelemetry-dotnet-tests-1           |      Passed: 26
opentelemetry-dotnet-tests-1           |  Total time: 1.0136 Minutes
opentelemetry-dotnet-tests-1 exited with code 0
Aborting on container exit...
[+] Stopping 2/0
 ✔ Container opentelemetry-dotnet-tests-1           Stopped                0.0s 
 ✔ Container opentelemetry-dotnet-otel-collector-1  Stopped                0.1

Oh I re-produced the error, let me fix it.