]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/api/prometheus.service.spec.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / api / prometheus.service.spec.ts
index db14f4679c1128cc7bf862625c73397092e76005..b7e4e565ac0578563231203f7e9c8db04106e0ed 100644 (file)
@@ -79,15 +79,90 @@ describe('PrometheusService', () => {
     expect(req.request.method).toBe('GET');
   });
 
-  it('should get prometheus rules', () => {
-    service.getRules({}).subscribe();
-    const req = httpTesting.expectOne('api/prometheus/rules');
-    expect(req.request.method).toBe('GET');
+  describe('test getRules()', () => {
+    let data: {}; // Subset of PrometheusRuleGroup to keep the tests concise.
+
+    beforeEach(() => {
+      data = {
+        groups: [
+          {
+            name: 'test',
+            rules: [
+              {
+                name: 'load_0',
+                type: 'alerting'
+              },
+              {
+                name: 'load_1',
+                type: 'alerting'
+              },
+              {
+                name: 'load_2',
+                type: 'alerting'
+              }
+            ]
+          },
+          {
+            name: 'recording_rule',
+            rules: [
+              {
+                name: 'node_memory_MemUsed_percent',
+                type: 'recording'
+              }
+            ]
+          }
+        ]
+      };
+    });
+
+    it('should get rules without applying filters', () => {
+      service.getRules().subscribe((rules) => {
+        expect(rules).toEqual(data);
+      });
+
+      const req = httpTesting.expectOne('api/prometheus/rules');
+      expect(req.request.method).toBe('GET');
+      req.flush(data);
+    });
+
+    it('should get rewrite rules only', () => {
+      service.getRules('rewrites').subscribe((rules) => {
+        expect(rules).toEqual({
+          groups: [{ name: 'test', rules: [] }, { name: 'recording_rule', rules: [] }]
+        });
+      });
+
+      const req = httpTesting.expectOne('api/prometheus/rules');
+      expect(req.request.method).toBe('GET');
+      req.flush(data);
+    });
+
+    it('should get alerting rules only', () => {
+      service.getRules('alerting').subscribe((rules) => {
+        expect(rules).toEqual({
+          groups: [
+            {
+              name: 'test',
+              rules: [
+                { name: 'load_0', type: 'alerting' },
+                { name: 'load_1', type: 'alerting' },
+                { name: 'load_2', type: 'alerting' }
+              ]
+            },
+            { name: 'recording_rule', rules: [] }
+          ]
+        });
+      });
+
+      const req = httpTesting.expectOne('api/prometheus/rules');
+      expect(req.request.method).toBe('GET');
+      req.flush(data);
+    });
   });
 
   describe('ifAlertmanagerConfigured', () => {
     let x: any;
-    let host;
+    let host: string;
 
     const receiveConfig = () => {
       const req = httpTesting.expectOne('api/settings/alertmanager-api-host');
@@ -125,7 +200,7 @@ describe('PrometheusService', () => {
 
   describe('ifPrometheusConfigured', () => {
     let x: any;
-    let host;
+    let host: string;
 
     const receiveConfig = () => {
       const req = httpTesting.expectOne('api/settings/prometheus-api-host');