-
Notifications
You must be signed in to change notification settings - Fork 105
Integration tests for N1C metrics #1210
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fe69e1f
add metric tests
spencerugbo 01bca5b
update otel collector readme
spencerugbo 8823d6a
fix small issue with test
spencerugbo 4b2f2e7
Merge branch 'main' into integration-tests-for-n1c-metrics
spencerugbo 6f0ee80
update depedencies versions
spencerugbo ee3ce96
added metric generation and polling
spencerugbo 1b82de0
cleanup
spencerugbo 0b9052a
fix error with Makefile
spencerugbo d794543
fix file transfer from host to container
spencerugbo f4b8c96
Merge branch 'main' into integration-tests-for-n1c-metrics
spencerugbo 3ddbca4
add logging for grafana
spencerugbo 84805d7
Merge branch 'main' into integration-tests-for-n1c-metrics
spencerugbo 1bc688e
add new workflow job for metric tests
spencerugbo 95439fa
clean up lint issues
spencerugbo 324f2fe
Merge branch 'main' into integration-tests-for-n1c-metrics
spencerugbo a9e70db
Update ci.yml
spencerugbo 955da28
fix container network issue
spencerugbo 3ead6b0
add jwt fix
spencerugbo a78077b
change memory usage test
spencerugbo d51a591
cleanup
spencerugbo edf038e
fix test starttup
spencerugbo 66703e7
Merge branch 'main' into integration-tests-for-n1c-metrics
spencerugbo 55f1d19
address comments
spencerugbo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| // Copyright (c) F5, Inc. | ||
| // | ||
| // This source code is licensed under the Apache License, Version 2.0 license found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
|
|
||
| package metrics | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/nginx/agent/v3/test/integration/utils" | ||
|
|
||
| dto "github.com/prometheus/client_model/go" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| type MetricsTestSuite struct { | ||
| suite.Suite | ||
| ctx context.Context | ||
| teardownTest func(testing.TB) | ||
| metricFamilies map[string]*dto.MetricFamily | ||
| } | ||
|
|
||
| func (s *MetricsTestSuite) SetupSuite() { | ||
| s.ctx = context.Background() | ||
| s.teardownTest = utils.SetupMetricsTest(s.T()) | ||
| time.Sleep(30 * time.Second) | ||
| s.metricFamilies = utils.ScrapeCollectorMetricFamilies(s.T(), s.ctx, utils.MockCollectorStack.Otel) | ||
| } | ||
|
|
||
| func (s *MetricsTestSuite) TearDownSuite() { | ||
| s.teardownTest(s.T()) | ||
| } | ||
|
|
||
| func (s *MetricsTestSuite) TestNginxOSS_Test1_TestRequestCount() { | ||
craigell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| family := s.metricFamilies["nginx_http_request_count"] | ||
| s.T().Logf("nginx_http_request_count metric family: %v", family) | ||
| s.Require().NotNil(family) | ||
|
|
||
| baselineMetric := utils.SumMetricFamily(family) | ||
| s.T().Logf("NGINX HTTP request count total: %v", baselineMetric) | ||
|
|
||
| requestCount := 5 | ||
| for range requestCount { | ||
| url := "http://127.0.0.1/" | ||
| _, _, err := utils.MockCollectorStack.AgentOSS.Exec( | ||
| s.ctx, | ||
| []string{"curl", "-s", url}, | ||
| ) | ||
| s.Require().NoError(err) | ||
| } | ||
|
|
||
| time.Sleep(65 * time.Second) | ||
craigell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| s.metricFamilies = utils.ScrapeCollectorMetricFamilies(s.T(), s.ctx, utils.MockCollectorStack.Otel) | ||
| family = s.metricFamilies["nginx_http_request_count"] | ||
| s.T().Logf("nginx_http_request_count metric family: %v", family) | ||
| s.Require().NotNil(family) | ||
|
|
||
| got := utils.SumMetricFamily(family) | ||
|
|
||
| s.T().Logf("NGINX HTTP request count total: %v", got) | ||
| s.Require().GreaterOrEqual(got, baselineMetric+float64(requestCount)) | ||
| } | ||
|
|
||
| func (s *MetricsTestSuite) TestNginxOSS_Test2_TestResponseCode() { | ||
| family := s.metricFamilies["nginx_http_response_count"] | ||
craigell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| s.T().Logf("nginx_http_response_count family: %v", family) | ||
| s.Require().NotNil(family) | ||
|
|
||
| responseCodes := []string{"1xx", "2xx", "3xx", "4xx"} | ||
| codeRes := make([]float64, 0, len(responseCodes)) | ||
| for code := range responseCodes { | ||
| codeRes = append(codeRes, utils.SumMetricFamilyLabel(family, "nginx_status_range", responseCodes[code])) | ||
| s.T().Logf("NGINX HTTP response code %s total: %v", responseCodes[code], codeRes[code]) | ||
| s.Require().NotNil(codeRes[code]) | ||
craigell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| func (s *MetricsTestSuite) TestHostMetrics_Test1_TestSystemCPUUtilization() { | ||
| family := s.metricFamilies["system_cpu_utilization"] | ||
| s.T().Logf("system_cpu_utilization metric family: %v", family) | ||
| s.Require().NotNil(family) | ||
|
|
||
| cpuUtilizationSystem := utils.SumMetricFamilyLabel(family, "state", "system") | ||
| cpuUtilizationUser := utils.SumMetricFamilyLabel(family, "state", "user") | ||
|
|
||
| s.T().Logf("System cpu utilization: %v", cpuUtilizationSystem) | ||
| s.T().Logf("System cpu utilization: %v", cpuUtilizationUser) | ||
| s.Require().NotNil(cpuUtilizationSystem) | ||
| s.Require().NotNil(cpuUtilizationUser) | ||
| } | ||
|
|
||
| func (s *MetricsTestSuite) TestHostMetrics_Test2_TestSystemMemoryUsage() { | ||
| family := s.metricFamilies["system_memory_usage"] | ||
| s.T().Logf("system_memory_usage metric family: %v", family) | ||
| s.Require().NotNil(family) | ||
|
|
||
| memoryUsageFree := utils.SumMetricFamilyLabel(family, "state", "free") | ||
| memoryUsageUsed := utils.SumMetricFamilyLabel(family, "state", "used") | ||
|
|
||
| s.T().Logf("System memory usage: %v", memoryUsageFree) | ||
| s.T().Logf("System memory usage: %v", memoryUsageUsed) | ||
| s.Require().NotNil(memoryUsageFree) | ||
| s.Require().NotNil(memoryUsageUsed) | ||
| } | ||
|
|
||
| func TestMetricsTestSuite(t *testing.T) { | ||
| suite.Run(t, new(MetricsTestSuite)) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.