Bug 2188193

Summary: grafana-9.0.9-2 FTBFS due to erroneous test using date in the past
Product: Red Hat Enterprise Linux 9 Reporter: Neil Hanlon <neil>
Component: grafanaAssignee: Grafana Maintenance <grafana-maint>
Status: CLOSED ERRATA QA Contact: Jan Kurik <jkurik>
Severity: low Docs Contact: Jacob Taylor Valdez <jvaldez>
Priority: unspecified    
Version: CentOS StreamCC: bstinson, dsmith, jkurik, jwboyer, nathans, scox
Target Milestone: rcKeywords: Triaged
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: grafana-9.2.10-3.el9 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-11-07 08:32:20 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
0011-v9.0.x-Alerting-Fix-integration-test-for-creating-silences.patch none

Description Neil Hanlon 2023-04-20 03:50:40 UTC
Description of problem: fails three tests due to a hard-coded date used as the end date of alerts created inside the tests.

https://github.com/grafana/grafana/pull/65722

Version-Release number of selected component (if applicable): 9.0.9-2

How reproducible: always

Steps to Reproduce:

1. Rebuild grafana-9.0.9-2 against current build root with tests enabled
2. Review rpmbuild failure due to building after March 31, 2023.

Actual results:

Tests fail unexpectedly

Expected results:

Tests complete successfully

Additional info:

Originally, the error will look like this, obscuring the error.

```
--- FAIL: TestAMConfigAccess (0.40s)
    testinfra.go:31: Grafana is listening on 127.0.0.1:41275
    --- FAIL: TestAMConfigAccess/when_creating_silence (0.03s)
        --- FAIL: TestAMConfigAccess/when_creating_silence/editor_request_should_succeed (0.01s)
            api_alertmanager_test.go:264: 
                	Error Trace:	api_alertmanager_test.go:264
                	Error:      	Not equal: 
                	            	expected: 202
                	            	actual  : 400
                	Test:       	TestAMConfigAccess/when_creating_silence/editor_request_should_succeed
        --- FAIL: TestAMConfigAccess/when_creating_silence/admin_request_should_succeed (0.01s)
            api_alertmanager_test.go:264: 
                	Error Trace:	api_alertmanager_test.go:264
                	Error:      	Not equal: 
                	            	expected: 202
                	            	actual  : 400
                	Test:       	TestAMConfigAccess/when_creating_silence/admin_request_should_succeed
    api_alertmanager_test.go:325: 
        	Error Trace:	api_alertmanager_test.go:325
        	Error:      	"[]" should have 2 item(s), but has 0
        	Test:       	TestAMConfigAccess
    --- FAIL: TestAMConfigAccess/when_deleting_a_silence (0.00s)
        --- FAIL: TestAMConfigAccess/when_deleting_a_silence/un-authenticated_request_should_fail (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0
goroutine 3163 [running]:
testing.tRunner.func1.2({0x3174960, 0xc0022fb650})
	/usr/lib/golang/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
	/usr/lib/golang/src/testing/testing.go:1399 +0x39f
panic({0x3174960, 0xc0022fb650})
	/usr/lib/golang/src/runtime/panic.go:884 +0x212
github.com/grafana/grafana/pkg/tests/api/alerting.TestAMConfigAccess.func5.1(0xc003cb1520)
	/builddir/build/BUILD/grafana-9.0.9/pkg/tests/api/alerting/api_alertmanager_test.go:362 +0x3d7
testing.tRunner(0xc003cb1520, 0xc003cc1440)
	/usr/lib/golang/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
	/usr/lib/golang/src/testing/testing.go:1493 +0x35f
FAIL	github.com/grafana/grafana/pkg/tests/api/alerting	34.904s
```

Upon patching the test to fail on the response body instead, we observe the actual error which was obscured by the test's evaluation of the response code before response body.

```
--- FAIL: TestAMConfigAccess (0.30s)
    testinfra.go:31: Grafana is listening on 127.0.0.1:35835
    --- FAIL: TestAMConfigAccess/when_creating_silence (0.03s)
        --- FAIL: TestAMConfigAccess/when_creating_silence/editor_request_should_succeed (0.01s)
            api_alertmanager_test.go:270: 
                    Error Trace:    api_alertmanager_test.go:270
                    Error:          "{\"message\":\"end time can't be in the past: unable to create silence\",\"traceID\":\"00000000000000000000000000000000\"}" does not contain "{\"id\":\"0\",\"message\":\"silence created\"}"
                    Test:           TestAMConfigAccess/when_creating_silence/editor_request_should_succeed
        --- FAIL: TestAMConfigAccess/when_creating_silence/admin_request_should_succeed (0.01s)
            api_alertmanager_test.go:270: 
                    Error Trace:    api_alertmanager_test.go:270
                    Error:          "{\"message\":\"end time can't be in the past: unable to create silence\",\"traceID\":\"00000000000000000000000000000000\"}" does not contain "{\"id\":\"0\",\"message\":\"silence created\"}"
                    Test:           TestAMConfigAccess/when_creating_silence/admin_request_should_succeed
    api_alertmanager_test.go:325: 
            Error Trace:    api_alertmanager_test.go:325
            Error:          "[]" should have 2 item(s), but has 0
            Test:           TestAMConfigAccess
    --- FAIL: TestAMConfigAccess/when_deleting_a_silence (0.00s)
        --- FAIL: TestAMConfigAccess/when_deleting_a_silence/un-authenticated_request_should_fail (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
    panic: runtime error: index out of range [0] with length 0
```

Comment 1 Neil Hanlon 2023-04-20 03:56:39 UTC
Created attachment 1958449 [details]
0011-v9.0.x-Alerting-Fix-integration-test-for-creating-silences.patch

Comment 2 Stan Cox 2023-04-25 16:13:37 UTC
Came across this as well.  Thanks for the patch.

Comment 3 Neil Hanlon 2023-04-25 16:15:34 UTC
(In reply to Stan Cox from comment #2)
> Came across this as well.  Thanks for the patch.

Of course, happy to help. I did open an MR for Stream here: https://gitlab.com/redhat/centos-stream/rpms/grafana/-/merge_requests/21

Comment 7 errata-xmlrpc 2023-11-07 08:32:20 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (Moderate: grafana security and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2023:6420