|
1 | 1 | package alerts |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
| 5 | + "fmt" |
4 | 6 | . "github.com/onsi/ginkgo" |
5 | 7 | . "github.com/onsi/gomega" |
| 8 | + . "github.com/onsi/gomega/gstruct" |
| 9 | + v1 "github.com/prometheus/client_golang/api/prometheus/v1" |
| 10 | + "github.com/prometheus/common/model" |
| 11 | + "github.com/smartcontractkit/integrations-framework/chaos" |
| 12 | + "github.com/smartcontractkit/integrations-framework/chaos/experiments" |
6 | 13 | "github.com/smartcontractkit/integrations-framework/environment" |
| 14 | + "github.com/smartcontractkit/integrations-framework/suite/steps" |
7 | 15 | "github.com/smartcontractkit/integrations-framework/suite/testcommon" |
8 | 16 | ) |
9 | 17 |
|
10 | | -var _ = Describe("Alerts suite", func() { |
11 | | - Describe("Alerts", func() { |
12 | | - It("Deploys the alerts stack up to Prometheus", func() { |
13 | | - i := &testcommon.OCRSetupInputs{} |
14 | | - testcommon.DeployOCRForEnv(i, "basic-chainlink", environment.NewChainlinkClusterForAlertsTesting(5)) |
15 | | - testcommon.SetupOCRTest(i) |
16 | | - testcommon.CheckRound(i) |
17 | | - testcommon.WriteDataForOTPEToInitializerFileForMockserver(i) |
| 18 | +var _ = Describe("OCR Alerts suite", func() { |
| 19 | + var ( |
| 20 | + testSetup *testcommon.OCRSetupInputs |
| 21 | + ) |
18 | 22 |
|
19 | | - err := i.SuiteSetup.Env.DeploySpecs(environment.OtpeGroup()) |
| 23 | + BeforeEach(func() { |
| 24 | + By("Deploying the basic environment", func() { |
| 25 | + testSetup = &testcommon.OCRSetupInputs{} |
| 26 | + testcommon.DeployOCRForEnv( |
| 27 | + testSetup, |
| 28 | + "basic-chainlink", |
| 29 | + environment.NewChainlinkClusterForAlertsTesting(6), |
| 30 | + ) |
| 31 | + testcommon.SetupOCRTest(testSetup) |
| 32 | + }) |
| 33 | + |
| 34 | + By("Creating initializer file for mockserver", func() { |
| 35 | + steps.WriteDataForOTPEToInitializerFileForMockserver( |
| 36 | + testSetup.OCRInstance.Address(), |
| 37 | + testSetup.ChainlinkNodes, |
| 38 | + ) |
| 39 | + }) |
| 40 | + |
| 41 | + By("Deploying otpe and prometheus", func() { |
| 42 | + err := testSetup.SuiteSetup.Env.DeploySpecs(environment.OtpeGroup()) |
| 43 | + Expect(err).ShouldNot(HaveOccurred()) |
| 44 | + |
| 45 | + err = testSetup.SuiteSetup.Env.DeploySpecs(environment.PrometheusGroup()) |
20 | 46 | Expect(err).ShouldNot(HaveOccurred()) |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + Describe("Telemetry Down Alerts", func() { |
| 51 | + It("Doesn't start the OCR protocol", func() { |
| 52 | + prometheus, err := environment.GetPrometheusClientFromEnv(testSetup.SuiteSetup.Env) |
| 53 | + Expect(err).ShouldNot(HaveOccurred()) |
| 54 | + |
| 55 | + Eventually(func(g Gomega) []v1.Alert { |
| 56 | + alerts, err := prometheus.Alerts(context.Background()) |
| 57 | + g.Expect(err).ShouldNot(HaveOccurred()) |
| 58 | + return alerts.Alerts |
| 59 | + }, "5m", "15s").Should(ContainElement(MatchFields(IgnoreExtras, Fields{ |
| 60 | + "Labels": MatchKeys(IgnoreExtras, Keys{ |
| 61 | + model.LabelName("alertname"): Equal(model.LabelValue("Telemetry Down (infra)")), |
| 62 | + }), |
| 63 | + "State": Equal(v1.AlertState("firing")), |
| 64 | + }))) |
| 65 | + }) |
| 66 | + |
| 67 | + It("Shuts down all chainlink nodes after some successful rounds", func() { |
| 68 | + testcommon.SendOCRJobs(testSetup) |
| 69 | + testcommon.CheckRound(testSetup) |
| 70 | + |
| 71 | + experimentSpecs := make([]chaos.Experimentable, len(testSetup.ChainlinkNodes[1:])) |
| 72 | + |
| 73 | + for i := 0; i < len(testSetup.ChainlinkNodes[1:]); i++ { |
| 74 | + experimentSpecs[i] = &experiments.PodKill{ |
| 75 | + TargetAppLabel: fmt.Sprintf("chainlink-%d", i+1), |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + for _, experimentSpec := range experimentSpecs { |
| 80 | + _, err := testSetup.SuiteSetup.Env.ApplyChaos(experimentSpec) |
| 81 | + Expect(err).ShouldNot(HaveOccurred()) |
| 82 | + } |
| 83 | + |
| 84 | + prometheus, err := environment.GetPrometheusClientFromEnv(testSetup.SuiteSetup.Env) |
| 85 | + Expect(err).ShouldNot(HaveOccurred()) |
| 86 | + |
| 87 | + Eventually(func(g Gomega) []v1.Alert { |
| 88 | + alerts, err := prometheus.Alerts(context.Background()) |
| 89 | + g.Expect(err).ShouldNot(HaveOccurred()) |
| 90 | + return alerts.Alerts |
| 91 | + }, "5m", "15s").Should(ContainElement(MatchFields(IgnoreExtras, Fields{ |
| 92 | + "Labels": MatchKeys(IgnoreExtras, Keys{ |
| 93 | + model.LabelName("alertname"): Equal(model.LabelValue("Telemetry Down (infra)")), |
| 94 | + }), |
| 95 | + "State": Equal(v1.AlertState("firing")), |
| 96 | + }))) |
| 97 | + }) |
| 98 | + }) |
21 | 99 |
|
22 | | - err = i.SuiteSetup.Env.DeploySpecs(environment.PrometheusGroup()) |
| 100 | + AfterEach(func() { |
| 101 | + By("Stop chaos", func() { |
| 102 | + err := testSetup.SuiteSetup.Env.StopAllChaos() |
23 | 103 | Expect(err).ShouldNot(HaveOccurred()) |
24 | 104 | }) |
| 105 | + By("Tearing down the environment", testSetup.SuiteSetup.TearDown()) |
25 | 106 | }) |
26 | 107 | }) |
0 commit comments