Search in sources :

Example 1 with ResourceMetrics

use of com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics in project photon-model by vmware.

the class LongRunEndToEndStatsAggregationTest method verifyTimeBinMetrics.

/**
 * Performs check to verify time bin metrics are available for every compute resource and also
 * checks the occurrence of estimated charges for one of the resource metrics.
 */
private void verifyTimeBinMetrics(ServiceDocumentQueryResult res) {
    List<Object> results = new ArrayList<>();
    for (String computeResourceLink : res.documentLinks) {
        for (String metricName : TestAWSSetupUtils.getMetricNames()) {
            QueryTask.QuerySpecification querySpec = new QueryTask.QuerySpecification();
            querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, computeResourceLink), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(QuerySpecification.buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metricName), NumericRange.createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build();
            QueryTask qt = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.TOP_RESULTS).addOption(QueryTask.QuerySpecification.QueryOption.INCLUDE_ALL_VERSIONS).setResultLimit(1).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).addOption(QueryTask.QuerySpecification.QueryOption.SORT).orderDescending(ServiceDocument.FIELD_NAME_SELF_LINK, ServiceDocumentDescription.TypeName.STRING).setQuery(querySpec.query).build();
            this.host.createQueryTaskService(qt, false, true, qt, null);
            if (qt.results.documentLinks.size() > 0 && qt.results.documentLinks.get(0) != null) {
                results.add(qt.results.documents.get(qt.results.documentLinks.get(0)));
            }
        }
    }
    long expectedExpirationTime = Utils.getNowMicrosUtc() + TimeUnit.DAYS.toMicros(DEFAULT_RETENTION_LIMIT_DAYS);
    boolean estimatedChargeFound = false;
    for (Object aggrDocument : results) {
        ResourceMetrics aggrMetric = Utils.fromJson(aggrDocument, ResourceMetrics.class);
        // Make sure all the documents have expiration time set.
        assertTrue("Expiration time is not correctly set.", aggrMetric.documentExpirationTimeMicros < expectedExpirationTime);
        // The assertion here checks whether we are aggregating only on latest value. To
        // that effect, here is the breakdown for the check:
        // count = num of resources: one value for each resource
        // sum = null: not specified in the aggregate type set
        assertNotNull("Value is not set", aggrMetric.entries.get(0));
    }
    assertTrue(estimatedChargeFound);
}
Also used : QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask) ArrayList(java.util.ArrayList) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification)

Example 2 with ResourceMetrics

use of com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics in project photon-model by vmware.

the class LongRunEndToEndStatsCollectionTest method getResourceMetrics.

/**
 * Method returns ResourceMetrics collected during stats collection for a resource endpoint
 * for the given resource metric key.
 */
private ResourceMetrics getResourceMetrics(String resourceLink, String metricKey) {
    QueryTask qt = QueryTask.Builder.createDirectTask().addOption(QueryOption.TOP_RESULTS).addOption(QueryOption.INCLUDE_ALL_VERSIONS).setResultLimit(1).addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.SORT).orderDescending(ServiceDocument.FIELD_NAME_SELF_LINK, ServiceDocumentDescription.TypeName.STRING).setQuery(QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, UriUtils.getLastPathSegment(resourceLink)), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(QueryTask.QuerySpecification.buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metricKey), QueryTask.NumericRange.createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build()).build();
    this.host.createQueryTaskService(qt, false, true, qt, null);
    ResourceMetrics resourceMetric = null;
    if (qt.results.documentLinks.size() > 0) {
        String documentLink = qt.results.documentLinks.get(0);
        resourceMetric = Utils.fromJson(qt.results.documents.get(documentLink), ResourceMetrics.class);
    }
    return resourceMetric;
}
Also used : ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask)

Example 3 with ResourceMetrics

use of com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics in project photon-model by vmware.

the class TestAWSCostAdapterService method verifyPersistedStats.

private void verifyPersistedStats(EndpointAllocationTaskState completeState, String metric, int expectedCount) {
    this.host.waitFor("Timeout waiting for stats", () -> {
        QueryTask.QuerySpecification querySpec = new QueryTask.QuerySpecification();
        querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, UriUtils.getLastPathSegment(completeState.endpointState.computeLink)), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metric), createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build();
        querySpec.options.add(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT);
        ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(querySpec, expectedCount, expectedCount);
        boolean statsCollected = true;
        for (Object metrics : result.documents.values()) {
            ResourceMetrics rawMetrics = Utils.fromJson(metrics, ResourceMetrics.class);
            Double rawMetric = rawMetrics.entries.get(metric);
            if (rawMetric != null) {
                continue;
            }
            statsCollected = false;
        }
        if (metric.equalsIgnoreCase(AWSConstants.COST)) {
            List<ResourceMetrics> accountOneTimeCharges = result.documents.values().stream().map(o -> Utils.fromJson(o, ResourceMetrics.class)).filter(m -> m.entries.containsKey(PhotonModelConstants.ACCOUNT_ONE_TIME_CHARGES)).collect(Collectors.toList());
            if (accountOneTimeCharges.size() != result.documentCount) {
                statsCollected = false;
            }
        }
        return statsCollected;
    });
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) QueryTask(com.vmware.xenon.services.common.QueryTask) StatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService.StatsCollectionTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) Utils(com.vmware.xenon.common.Utils) QuerySpecification.buildCompositeFieldName(com.vmware.xenon.services.common.QueryTask.QuerySpecification.buildCompositeFieldName) Map(java.util.Map) After(org.junit.After) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) StatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.StatsCollectionTaskService) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) INSTANCE_1_SELF_LINK(com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_1_SELF_LINK) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) AwsServices(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices) TaskOption(com.vmware.photon.controller.model.tasks.TaskOption) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) Function(java.util.function.Function) ArrayList(java.util.ArrayList) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) NumericRange.createDoubleRange(com.vmware.xenon.services.common.QueryTask.NumericRange.createDoubleRange) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) Operation(com.vmware.xenon.common.Operation) Assert.assertTrue(org.junit.Assert.assertTrue) SingleResourceStatsCollectionTaskService(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService) Test(org.junit.Test) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) LocalDate(org.joda.time.LocalDate) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) AWSStatsNormalizer(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSStatsNormalizer) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) INSTANCE_2_SELF_LINK(com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_2_SELF_LINK) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 4 with ResourceMetrics

use of com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics in project photon-model by vmware.

the class AWSCostStatsService method filterAccountDetails.

private void filterAccountDetails(AWSCostStatsCreationContext context, AwsAccountDetailDto accountDto, String interval) {
    ResourceMetrics markerMetrics = context.accountsMarkersMap.get(accountDto.id);
    if (markerMetrics == null || interval == null) {
        return;
    }
    Double previousLineCount = markerMetrics.entries.get(interval);
    Integer currentLineCount = accountDto.lineCountPerInterval.get(interval);
    if (previousLineCount != null && currentLineCount != null && previousLineCount.intValue() == currentLineCount) {
        accountDto.serviceDetailsMap.clear();
    }
}
Also used : ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)

Example 5 with ResourceMetrics

use of com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics in project photon-model by vmware.

the class AWSCostStatsService method getMarkerMetricsOp.

private Operation getMarkerMetricsOp(AWSCostStatsCreationContext context, ComputeState accComputeState) {
    QueryTask qTask = getQueryTaskForMetric(accComputeState);
    Operation.CompletionHandler completionHandler = (operation, exception) -> {
        if (exception != null) {
            logWarning(() -> String.format("Failed to get bill processed time for account: %s", accComputeState.documentSelfLink));
            getFailureConsumer(context).accept(exception);
            return;
        }
        QueryTask body = operation.getBody(QueryTask.class);
        String accountId = accComputeState.customProperties.get(AWS_ACCOUNT_ID_KEY);
        if (body.results.documentCount == 0) {
            ResourceMetrics markerMetrics = new ResourceMetrics();
            markerMetrics.timestampMicrosUtc = getCurrentMonthStartTimeMicros();
            markerMetrics.entries = new HashMap<>();
            markerMetrics.entries.put(AWSConstants.AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS, 0d);
            markerMetrics.documentSelfLink = StatsUtil.getMetricKey(accComputeState.documentSelfLink, Utils.getNowMicrosUtc());
            context.accountsMarkersMap.put(accountId, markerMetrics);
        } else {
            ResourceMetrics markerMetrics = body.results.documents.values().stream().map(o -> Utils.fromJson(o, ResourceMetrics.class)).collect(Collectors.toList()).get(0);
            context.accountsMarkersMap.putIfAbsent(accountId, markerMetrics);
        }
    };
    return QueryUtils.createQueryTaskOperation(this, qTask, ServiceTypeCluster.METRIC_SERVICE).setExpiration(Utils.fromNowMicrosUtc(TimeUnit.SECONDS.toMicros(INTERNAL_REQUEST_TIMEOUT_SECONDS))).setCompletion(completionHandler);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS) AWSCsvBillParser(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) ProgressListener(com.amazonaws.event.ProgressListener) STORAGE_TYPE_EBS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.STORAGE_TYPE_EBS) Utils(com.vmware.xenon.common.Utils) STORAGE_TYPE_S3(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.STORAGE_TYPE_S3) ACCOUNT_IS_AUTO_DISCOVERED(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.ACCOUNT_IS_AUTO_DISCOVERED) Map(java.util.Map) URI(java.net.URI) ProgressEventType(com.amazonaws.event.ProgressEventType) AWSMissingResourcesEnumerationService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSMissingResourcesEnumerationService) Path(java.nio.file.Path) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) PrintWriter(java.io.PrintWriter) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AwsServiceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto) Objects(java.util.Objects) List(java.util.List) AWS_LINKED_ACCOUNT_IDS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_LINKED_ACCOUNT_IDS) Stream(java.util.stream.Stream) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) AwsServices(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) SingleResourceTaskCollectionStage(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage) AwsAccountDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsAccountDetailDto) TransferManager(com.amazonaws.services.s3.transfer.TransferManager) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) OperationContext(com.vmware.xenon.common.OperationContext) AWS_ACCOUNT_ID_KEY(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_ID_KEY) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ProgressEvent(com.amazonaws.event.ProgressEvent) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) BiConsumer(java.util.function.BiConsumer) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) AwsClientType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType) StatsUtil(com.vmware.photon.controller.model.tasks.monitoring.StatsUtil) ExecutorService(java.util.concurrent.ExecutorService) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) IOException(java.io.IOException) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) AwsResourceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) LocalDate(org.joda.time.LocalDate) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Paths(java.nio.file.Paths) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) AWSStatsNormalizer(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSStatsNormalizer) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) QueryTask(com.vmware.xenon.services.common.QueryTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Operation(com.vmware.xenon.common.Operation)

Aggregations

ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)31 QueryTask (com.vmware.xenon.services.common.QueryTask)19 ArrayList (java.util.ArrayList)12 Operation (com.vmware.xenon.common.Operation)10 Query (com.vmware.xenon.services.common.QueryTask.Query)9 HashMap (java.util.HashMap)9 Map (java.util.Map)9 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)7 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)7 URI (java.net.URI)7 ServiceStats (com.vmware.xenon.common.ServiceStats)6 ResourceMetricsService (com.vmware.photon.controller.model.monitoring.ResourceMetricsService)5 SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)5 ServiceDocument (com.vmware.xenon.common.ServiceDocument)5 UriUtils (com.vmware.xenon.common.UriUtils)5 UriPaths (com.vmware.photon.controller.model.UriPaths)4 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)4 List (java.util.List)4 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)3 AwsServices (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices)3