feat: service monitor health check for all resources

Merge request reports

Loading
+3 −1
Changes for src/test/resources/hypo/orchestrators/orchestratorPrivate.feature: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -67,7 +67,6 @@ Scenario: Run full sequence once
  * match invSer.response.state == 'ACTIVE'
  # Get the terminated payload for end user


  # Force the string to be parsed as JSON
  * json asJson = foundNamespace
  * def cleanNamespace = asJson[0]
@@ -80,6 +79,9 @@ Scenario: Run full sequence once
  * def metricsDashboardUrl = invRes.metricsDashboardUrl
  * def logsDashboardUrl = invRes.logsDashboardUrl

  # Poll tmf-api until service.monitor reports a healthy resource for the service
  * call read('classpath:hypo/service.feature@checkServiceMonitorHealth') { auth_token: '#(auth_token)', serviceId: '#(serviceId)' }

  # 14) Telemetry checks
  #create and get token 
  * def grafanaTokenRes = call read('classpath:hypo/telemetry.feature@grafana-token') 
+3
Changes for src/test/resources/hypo/orchestrators/orchestratorPublic.feature: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@ Scenario: Run full sequence once
  * def metricsDashboardUrl = invRes.metricsDashboardUrl
  * def logsDashboardUrl = invRes.logsDashboardUrl

  # Poll tmf-api until service.monitor reports a healthy resource for the service
  * call read('classpath:hypo/service.feature@checkServiceMonitorHealth') { auth_token: '#(auth_token)', serviceId: '#(serviceId)' }

  # 14) Telemetry — metrics + prometheus + logs checks
  #create and get token 
  * def grafanaTokenRes = call read('classpath:hypo/telemetry.feature@grafana-token') 
+87
Changes for src/test/resources/hypo/service.feature: 87 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -360,6 +360,93 @@ Scenario: Get Resource Inventory and Extract Dashboard URLs
  * karate.log('Extracted Metrics URL:', metricsDashboardUrl)
  * karate.log('Extracted Logs URL:', logsDashboardUrl)

@getResourceById
Scenario: Get a single Resource by id
  Given url baseUrl
  And path 'tmf-api', 'resourceInventoryManagement', V4, 'resource', resourceId
  And header Authorization = 'Bearer ' + token
  When method get
  Then status 200

@checkServiceMonitorHealth
Scenario: Poll tmf-api until service.monitor reports all resources of the service as healthy
  * karate.log('--- POLLING FOR SERVICE MONITOR HEALTH REPORT ---')
  * karate.log('For Service ID:', serviceId)

  * def maxRetries = 15
  * def pollInterval = 15000
  * def requiredConsecutive = 2

  * def getMonitoredResources =
    """
    function() {
      var invSer = karate.call('classpath:hypo/service.feature@getServiceInventoryResource', { token: token, serviceId: serviceId });
      var refs = invSer.response.supportingResource || [];
      var monitored = [];
      for (var i = 0; i < refs.length; i++) {
        var resource = karate.call('classpath:hypo/service.feature@getResourceById', { token: token, resourceId: refs[i].id }).response;
        if (!resource['@type'] && resource.name) {
          monitored.push({ name: resource.name, operationalState: resource.operationalState || 'NONE' });
        }
      }
      monitored.sort(function(a, b) { return a.name < b.name ? -1 : a.name > b.name ? 1 : 0; });
      return monitored;
    }
    """

  * def describe =
    """
    function(monitored) {
      if (monitored.length === 0) return '(none)';
      var parts = [];
      for (var i = 0; i < monitored.length; i++) parts.push(monitored[i].name + '=' + monitored[i].operationalState);
      return parts.join(', ');
    }
    """

  * def allHealthy =
    """
    function(monitored) {
      if (monitored.length === 0) return false;
      for (var i = 0; i < monitored.length; i++) {
        if (monitored[i].operationalState !== 'ENABLE') return false;
      }
      return true;
    }
    """

  * def doPoll =
    """
    function() {
      var consecutive = 0;
      var previousNames = null;
      var last = [];
      for (var i = 0; i < maxRetries; i++) {
        last = getMonitoredResources();
        var summary = describe(last);
        var names = last.map(function(r) { return r.name; }).join(',');
        if (allHealthy(last)) {
          consecutive = (names === previousNames) ? consecutive + 1 : 1;
          karate.log('Attempt #' + (i + 1) + ' - all service.monitor resources healthy (' + consecutive + '/' + requiredConsecutive + '): ' + summary);
          if (consecutive >= requiredConsecutive) {
            karate.log('service.monitor health confirmed at attempt #' + (i + 1));
            return true;
          }
        } else {
          consecutive = 0;
          karate.log('Attempt #' + (i + 1) + ' - service.monitor resources not all healthy yet: ' + summary);
        }
        previousNames = names;
        if (i < maxRetries - 1) {
          java.lang.Thread.sleep(pollInterval);
        }
      }
      karate.fail('service.monitor did not report all resources healthy for service ' + serviceId + ' within ' + (maxRetries * pollInterval / 1000) + 's. Last state: ' + describe(last));
    }
    """

  * doPoll()

@terminateService
Scenario: Terminate the Service
  * karate.log('--- STEP: PATCH SERVICE TO TERMINATED ---')
Loading