Search in sources :

Example 1 with SingleResourceStatsCollectionTaskService

use of com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService in project photon-model by vmware.

the class LongRunEndToEndStatsCollectionTest method testStatsCollection.

/**
 * Test to perform end to end stats collection with stats adapter.
 * Performs enumeration against a real AWS endpoint if provided and then executes 2 sessions of
 * periodic stats collection.
 * Log the stats for Cpu and Memory usage.
 * Verifies the compute types of resources and their stats for last successful collection time.
 * Also, verifies Estimated Charges value for given AWS endpoint.
 */
@Test
public void testStatsCollection() throws Throwable {
    this.host.log("Running test: " + this.currentTestName);
    // if mock, simply return.
    if (this.isMock) {
        return;
    }
    this.host.log(STAT_NAME_MEMORY_ON_HOST_IN_MB + SEPARATOR + this.maxMemoryInMb);
    SingleResourceStatsCollectionTaskService service = new SingleResourceStatsCollectionTaskService();
    // generate stats link using stats adapter
    String statsLink = UriUtils.getLastPathSegment(AWSUriPaths.AWS_STATS_ADAPTER);
    this.lastSuccessfulCollectionTimeKey = service.getLastCollectionMetricKeyForAdapterLink(statsLink, true);
    // perform resource stats collection before enumeration takes place on given AWS endpoint
    resourceStatsCollection(this.host, this.isMock, this.computeHost.resourcePoolLink);
    // will try to fetch the compute state resources
    ServiceDocumentQueryResult result = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)));
    // will have only 1 document of type 'ENDPOINT_HOST'
    assertEquals(1, result.documents.size());
    JsonObject jsonObject = (JsonObject) result.documents.get(result.documentLinks.get(0));
    assertEquals(ComputeType.ENDPOINT_HOST.toString(), jsonObject.get("type").getAsString());
    // perform resource enumeration on given AWS endpoint
    enumerateResources(this.host, this.computeHost, this.endpointState, this.isMock, TEST_CASE_RUN);
    // periodically perform stats collection on given AWS endpoint
    runStatsCollectionLogNodeStatsPeriodically();
    this.host.log(Level.INFO, "Waiting for multiple stats collection runs...");
    // Keep the host running for some time, specified by testRunDurationInMinutes parameter.
    this.host.waitFor("Timeout while waiting for test run duration", () -> {
        TimeUnit.MINUTES.sleep(this.testRunDurationInMinutes);
        return true;
    });
    // fetch all the compute state resources
    ServiceDocumentQueryResult res = this.host.getFactoryState(UriUtils.buildExpandLinksQueryUri(UriUtils.buildUri(this.host, ComputeService.FACTORY_LINK)));
    // total compute resources
    this.totalComputeResources = res.documents.size();
    this.currentTimeMicros = Utils.getNowMicrosUtc();
    // query and verify resource metrics obtained for first iteration of stats collection
    verifyMetricStats(res, this.statsToCheckInit);
    // periodically perform more cycles of resource stats collection on given AWS endpoint
    this.host.log(Level.INFO, "Waiting for multiple stats collection second runs...");
    // Keep the host running for some time, specified by testRunDurationInMinutes parameter.
    this.host.waitFor("Timeout while waiting for second test run duration", () -> {
        TimeUnit.MINUTES.sleep(this.testRunDurationInMinutes);
        this.host.getScheduledExecutor().shutdown();
        this.host.getScheduledExecutor().awaitTermination(EXECUTOR_TERMINATION_WAIT_DURATION_MINUTES, TimeUnit.MINUTES);
        return true;
    });
    // query and verify resource metrics obtained for second iteration of stats collection
    verifyMetricStats(res, this.statsToCheckLater);
    // the values will change only if new values are captured from AWS during stats collection.
    assertTrue("LastUpdate time obtained during first cycle of stats collection should be" + " less than or equal to the value during second cycle", this.statsToCheckInit.serviceStat.lastUpdateMicrosUtc <= this.statsToCheckLater.serviceStat.lastUpdateMicrosUtc);
    assertTrue("LatestValue obtained during first cycle of stats collection should be " + "less than or equal to the value during second cycle", this.statsToCheckInit.serviceStat.latestValue <= this.statsToCheckLater.serviceStat.latestValue);
    assertTrue("Document version obtained during initial cycles of stats collection should be" + " less than or equal to that obtained during later stats collection cycle", this.statsToCheckInit.serviceStat.version <= this.statsToCheckInit.serviceStat.version);
    assertTrue("EstimatedCharges obtained during first cycle of stats collection should be" + " less than or equal to that obtained during second stats collection cycle", this.statsToCheckInit.estimatedCharges <= this.statsToCheckLater.estimatedCharges);
}
Also used : SingleResourceStatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService) JsonObject(com.google.gson.JsonObject) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

Aggregations

JsonObject (com.google.gson.JsonObject)1 SingleResourceStatsCollectionTaskService (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService)1 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)1 Test (org.junit.Test)1