/** * Delete the metrics for a profile. * * @param profileId the profile to delete metrics for. */ private void deleteMetrics(ProfileId profileId) { long endTs = System.currentTimeMillis() / 1000; Map<String, String> tags = new LinkedHashMap<>(); tags.put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()); tags.put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()); // if the profile is in user scope, we need to add the namespace info to distinguish the profile if (profileId.getScope().equals(EntityScope.USER)) { tags.put(Constants.Metrics.Tag.NAMESPACE, profileId.getNamespace()); } MetricDeleteQuery deleteQuery = new MetricDeleteQuery(0, endTs, Collections.emptySet(), tags, new ArrayList<>(tags.keySet())); metricStore.delete(deleteQuery); } }
/** * Delete the metrics for a profile. * * @param profileId the profile to delete metrics for. */ private void deleteMetrics(ProfileId profileId) { long endTs = System.currentTimeMillis() / 1000; Map<String, String> tags = new LinkedHashMap<>(); tags.put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()); tags.put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()); // if the profile is in user scope, we need to add the namespace info to distinguish the profile if (profileId.getScope().equals(EntityScope.USER)) { tags.put(Constants.Metrics.Tag.NAMESPACE, profileId.getNamespace()); } MetricDeleteQuery deleteQuery = new MetricDeleteQuery(0, endTs, Collections.emptySet(), tags, new ArrayList<>(tags.keySet())); metricStore.delete(deleteQuery); } }
/** * Get the metrics context for the program, the tags are constructed with the program run id and * the profile id */ private MetricsContext getMetricsContextForProfile(MetricsCollectionService metricsCollectionService, ProgramRunId programRunId, ProfileId profileId) { Map<String, String> tags = ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()) .build(); return metricsCollectionService.getContext(tags); } }
/** * Get the metrics context for the program, the tags are constructed with the program run id and * the profile id */ private MetricsContext getMetricsContextForProfile(MetricsCollectionService metricsCollectionService, ProgramRunId programRunId, ProfileId profileId) { Map<String, String> tags = ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()) .build(); return metricsCollectionService.getContext(tags); } }
/** * Emit the metrics context for the program, the tags are constructed with the program run id and * the profile id */ private void emitProfileMetrics(ProgramRunId programRunId, ProfileId profileId, String metricName) { Map<String, String> tags = ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()) .build(); metricsCollectionService.getContext(tags).increment(metricName, 1L); }
/** * Emit the metrics context for the program, the tags are constructed with the program run id and * the profile id */ private void emitProfileMetrics(ProgramRunId programRunId, ProfileId profileId, String metricName) { Map<String, String> tags = ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()) .build(); metricsCollectionService.getContext(tags).increment(metricName, 1L); }
private Map<String, String> getMetricsTags(ProgramRunId programRunId, ProfileId profileId) { return ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()) .build(); }
private void writeProfile(ProfileId profileId, FullHttpRequest request) throws BadRequestException, IOException, MethodNotAllowedException { ProfileCreateRequest profileCreateRequest; try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) { profileCreateRequest = GSON.fromJson(reader, ProfileCreateRequest.class); validateProvisionerProperties(profileCreateRequest); } catch (JsonSyntaxException e) { throw new BadRequestException("Unable to parse request body. Please make sure it is valid JSON", e); } Profile profile = new Profile(profileId.getProfile(), profileCreateRequest.getLabel(), profileCreateRequest.getDescription(), profileId.getScope(), profileCreateRequest.getProvisioner()); profileService.saveProfile(profileId, profile); }
private void writeProfile(ProfileId profileId, FullHttpRequest request) throws BadRequestException, IOException, MethodNotAllowedException { ProfileCreateRequest profileCreateRequest; try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) { profileCreateRequest = GSON.fromJson(reader, ProfileCreateRequest.class); validateProvisionerProperties(profileCreateRequest); } catch (JsonSyntaxException e) { throw new BadRequestException("Unable to parse request body. Please make sure it is valid JSON", e); } Profile profile = new Profile(profileId.getProfile(), profileCreateRequest.getLabel(), profileCreateRequest.getDescription(), profileId.getScope(), profileCreateRequest.getProvisioner()); profileService.saveProfile(profileId, profile); }
private long getMetric(MetricStore metricStore, ProgramRunId programRunId, ProfileId profileId, String metricName) { Map<String, String> tags = ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .build(); MetricDataQuery query = new MetricDataQuery(0, 0, Integer.MAX_VALUE, metricName, AggregationFunction.SUM, tags, new ArrayList<>()); Collection<MetricTimeSeries> result = metricStore.query(query); if (result.isEmpty()) { return 0; } List<TimeValue> timeValues = result.iterator().next().getTimeValues(); if (timeValues.isEmpty()) { return 0; } return timeValues.get(0).getValue(); } }
private long getMetric(MetricStore metricStore, ProgramRunId programRunId, ProfileId profileId, String metricName) { Map<String, String> tags = ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .build(); MetricDataQuery query = new MetricDataQuery(0, 0, Integer.MAX_VALUE, metricName, AggregationFunction.SUM, tags, new ArrayList<>()); Collection<MetricTimeSeries> result = metricStore.query(query); if (result.isEmpty()) { return 0; } List<TimeValue> timeValues = result.iterator().next().getTimeValues(); if (timeValues.isEmpty()) { return 0; } return timeValues.get(0).getValue(); } }