Skip to content

Commit eab3468

Browse files
committed
address PR feedback
1 parent 487a4af commit eab3468

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

internal/collector/nginxossreceiver/internal/scraper/stubstatus/stub_status_scraper_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func TestStubStatusScraper(t *testing.T) {
3939
err := stubStatusScraper.Start(context.Background(), componenttest.NewNopHost())
4040
require.NoError(t, err)
4141

42+
_, err = stubStatusScraper.Scrape(context.Background())
43+
require.NoError(t, err)
44+
45+
// To test the nginx.http.request.count metric calculation we need to set the previousRequests and
46+
// call scrape a second time as the first time it is called the previous requests is set using the API
47+
stubStatusScraper.previousRequests = 31070460
4248
actualMetrics, err := stubStatusScraper.Scrape(context.Background())
4349
require.NoError(t, err)
4450

internal/collector/nginxossreceiver/internal/scraper/stubstatus/testdata/expected.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ resourceMetrics:
6464
gauge:
6565
aggregationTemporality: 2
6666
dataPoints:
67-
- asInt: "0"
67+
- asInt: "5"
6868
timeUnixNano: "1000000"
6969
isMonotonic: true
7070
unit: requests

internal/collector/nginxplusreceiver/scraper_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ func TestScraper(t *testing.T) {
3030
scraper, err := newNginxPlusScraper(receivertest.NewNopSettings(), cfg)
3131
require.NoError(t, err)
3232

33+
_, err = scraper.scrape(context.Background())
34+
require.NoError(t, err)
35+
36+
// To test the nginx.http.response.count metric calculation we need to set the previousLocationZoneResponses &
37+
// previousSeverZoneResponses then call scrape a second time as the first time it is called the previous responses
38+
// are set using the API
39+
scraper.previousLocationZoneResponses = map[string]ResponseStatuses{
40+
"location_test": {
41+
oneHundredStatusRange: 3, // 4
42+
twoHundredStatusRange: 29, // 2
43+
threeHundredStatusRange: 0,
44+
fourHundredStatusRange: 1, // 2
45+
fiveHundredStatusRange: 0,
46+
},
47+
}
48+
49+
scraper.previousServerZoneResponses = map[string]ResponseStatuses{
50+
"test": {
51+
oneHundredStatusRange: 3, // 2
52+
twoHundredStatusRange: 0, // 29
53+
threeHundredStatusRange: 0,
54+
fourHundredStatusRange: 1, // 1
55+
fiveHundredStatusRange: 0,
56+
},
57+
}
58+
3359
actualMetrics, err := scraper.scrape(context.Background())
3460
require.NoError(t, err)
3561

internal/collector/nginxplusreceiver/testdata/expected.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ resourceMetrics:
21372137
gauge:
21382138
aggregationTemporality: 2
21392139
dataPoints:
2140-
- asInt: "0"
2140+
- asInt: "2"
21412141
attributes:
21422142
- key: nginx.status_range
21432143
value:
@@ -2148,7 +2148,7 @@ resourceMetrics:
21482148
- key: nginx.zone.type
21492149
value:
21502150
stringValue: SERVER
2151-
- asInt: "0"
2151+
- asInt: "29"
21522152
attributes:
21532153
- key: nginx.status_range
21542154
value:
@@ -2170,7 +2170,7 @@ resourceMetrics:
21702170
- key: nginx.zone.type
21712171
value:
21722172
stringValue: SERVER
2173-
- asInt: "0"
2173+
- asInt: "1"
21742174
attributes:
21752175
- key: nginx.status_range
21762176
value:
@@ -2192,7 +2192,7 @@ resourceMetrics:
21922192
- key: nginx.zone.type
21932193
value:
21942194
stringValue: SERVER
2195-
- asInt: "0"
2195+
- asInt: "4"
21962196
attributes:
21972197
- key: nginx.status_range
21982198
value:
@@ -2203,7 +2203,7 @@ resourceMetrics:
22032203
- key: nginx.zone.type
22042204
value:
22052205
stringValue: LOCATION
2206-
- asInt: "0"
2206+
- asInt: "2"
22072207
attributes:
22082208
- key: nginx.status_range
22092209
value:
@@ -2225,7 +2225,7 @@ resourceMetrics:
22252225
- key: nginx.zone.type
22262226
value:
22272227
stringValue: LOCATION
2228-
- asInt: "0"
2228+
- asInt: "2"
22292229
attributes:
22302230
- key: nginx.status_range
22312231
value:

0 commit comments

Comments
 (0)