Conversation
|
This is copying a significant amount of code from https://github.com/gophercloud/gophercloud/tree/main/internal/acceptance. I am going to create a ticket there about potentially trying to expose this code out instead of copying it. |
6a71182 to
1b6d7ae
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces comprehensive integration tests for the OpenStack exporter, enabling automated testing against live OpenStack services (Ironic, Nova, Neutron, Glance, Keystone, Placement) via DevStack in CI. The tests validate that the exporter correctly generates Prometheus metrics from real OpenStack resources.
Key Changes
- Added integration test infrastructure with helper packages for creating test resources and clients
- Created service-specific integration test suites (baremetal, compute, networking, images, identity, placement)
- Set up GitHub Actions workflows to run integration tests on pull requests using DevStack
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 18 comments.
Show a summary per file
| File | Description |
|---|---|
| script/stackenv | Bash script to prepare DevStack testing environment with required resources and environment variables |
| script/integration-suites/* | Individual test runner scripts for each OpenStack service integration test suite |
| script/collectlogs | Utility script to collect diagnostic logs after integration test failures |
| integration/utils.go | Core integration test utilities for starting the OpenStack exporter |
| integration/tools/tools.go | Helper functions for waiting, random generation, and resource printing in tests |
| integration/tools/pkg.go | Build tags and package documentation for test tools |
| integration/funcs/compute.go | Helper functions for creating and managing compute resources in tests |
| integration/funcs/baremetal.go | Helper functions for creating and managing baremetal nodes in tests |
| integration/funcs/pkg.go | Build tags and package documentation for test resource functions |
| integration/clients/clients.go | OpenStack service client creation functions for various services |
| integration/clients/conditions.go | Test skip conditions for different OpenStack configurations and features |
| integration/clients/http.go | HTTP round tripper with request/response logging and header redaction |
| integration/*_test.go | Integration test files validating exporter metrics for each OpenStack service |
| .github/workflows/integration-*.yaml | GitHub Actions workflows for running integration tests in CI |
| .github/workflows/ci.yaml | Updated to exclude integration tests from unit test runs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| fetchMetrics := func( | ||
| url string, | ||
| maxTries int, | ||
| ) (resp *http.Response, body []byte, err error) { | ||
| for i := 0; i < maxTries; i++ { | ||
| resp, err = http.Get(url) | ||
| if err == nil && resp.StatusCode == http.StatusOK { | ||
| defer resp.Body.Close() | ||
| body, err = io.ReadAll(resp.Body) | ||
| if err == nil { | ||
| return resp, body, nil | ||
| } | ||
| t.Logf( | ||
| "Attempt %d: Failed to read response body: %v", | ||
| i+1, | ||
| err, | ||
| ) | ||
| } else { | ||
| var statusCode int | ||
| if resp != nil { | ||
| statusCode = resp.StatusCode | ||
| } | ||
| t.Logf( | ||
| "Attempt %d: Failed to get metrics, status code: %d, error: %v", | ||
| i+1, | ||
| statusCode, | ||
| err, | ||
| ) | ||
| } | ||
| if resp != nil && resp.Body != nil { | ||
| resp.Body.Close() | ||
| } | ||
| time.Sleep(1 * time.Second) | ||
| } | ||
| if err != nil { | ||
| return nil, nil, fmt.Errorf( | ||
| "failed to get metrics after %d retries: %w", | ||
| maxTries, | ||
| err, | ||
| ) | ||
| } | ||
| return nil, nil, fmt.Errorf( | ||
| "failed to get metrics after %d retries, but the error is nil (this should not happen)", | ||
| maxTries, | ||
| ) | ||
| } |
There was a problem hiding this comment.
There's significant code duplication in the fetchMetrics function across multiple test files (networking_test.go, images_test.go, identity_test.go, baremetal_test.go). This identical function should be extracted to a shared helper in integration/utils.go or a similar location to improve maintainability.
CI Fixes Fixing more lint errors Tried to make tests more specific Fixed issues Fixes Fixes More fixes Trying more Test Fix Testing Testing Changes Removing placement Trying things out More changes Testing Trying things Fixes Fixes chore(deps): bump actions/checkout from 4 to 6 Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Commits](actions/checkout@v4...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Update integration/funcs/compute.go Co-authored-by: Copilot <[email protected]> Update script/stackenv Co-authored-by: Copilot <[email protected]> chore(deps): bump reviewdog/action-actionlint from 1.66.1 to 1.69.0 Bumps [reviewdog/action-actionlint](https://github.com/reviewdog/action-actionlint) from 1.66.1 to 1.69.0. - [Release notes](https://github.com/reviewdog/action-actionlint/releases) - [Commits](reviewdog/action-actionlint@e37e2ca...437bbe9) --- updated-dependencies: - dependency-name: reviewdog/action-actionlint dependency-version: 1.69.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]>
7a9117f to
35eba72
Compare
|
|
I think the main thing to not is BASIS_OPS for ironic is false. For some reason, this makes the tests pass, where they didn't before |
|
@vooon - I'd appreciate your feedback on this in any capacity |
| - name: Checkout go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: '^1.22' |
There was a problem hiding this comment.
I think better to use that:
- uses: actions/setup-go@v6
with:
go-version-file: go.mod| metricsURL := "http://localhost:9180/metrics" | ||
|
|
||
| // Helper function to fetch metrics with retries | ||
| fetchMetrics := func( |
There was a problem hiding this comment.
I think here Copilot's right - since it's the same, i'd move it to general function or make a test suite.
| ) | ||
| } | ||
|
|
||
| time.Sleep(10 * time.Second) |
There was a problem hiding this comment.
Better to avoid sleeps, if possible.
| return nil, err | ||
| } | ||
|
|
||
| client, err := openstack.AuthenticatedClient(context.TODO(), ao) |
There was a problem hiding this comment.
Again good candidate for test suite. Also i'd probably add some timeout to the context - just to fail if there some problem with connectivity, instead of hung till CI timeout.
|
|
||
| // LogRoundTripper satisfies the http.RoundTripper interface and is used to | ||
| // customize the default http client RoundTripper to allow logging. | ||
| type LogRoundTripper struct { |
There was a problem hiding this comment.
Probably easier to use logger from gophercloud utils (present for both v1 and v2).
https://github.com/gophercloud/utils/blob/main/client/client.go
|
@vooon appreciate this. Thank you! |
This should help make trusting new changes easier.