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);
}
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;
}
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;
});
}
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();
}
}
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);
}
Aggregations