/** * * * <pre> * The associated metric. A fully-specified metric used to identify the time * series. * </pre> * * <code>.google.api.Metric metric = 1;</code> */ public Builder setMetric(com.google.api.Metric.Builder builderForValue) { if (metricBuilder_ == null) { metric_ = builderForValue.build(); onChanged(); } else { metricBuilder_.setMessage(builderForValue.build()); } return this; } /**
subBuilder.mergeFrom(metric_); metric_ = subBuilder.buildPartial();
subBuilder.mergeFrom(metric_); metric_ = subBuilder.buildPartial();
private TimeSeries createTimeSeries(Meter.Id id, TypedValue typedValue, MetricDescriptor.ValueType valueType, @Nullable String statistic) { if (client != null) createMetricDescriptorIfNecessary(client, id, valueType, statistic); String metricType = metricType(id, statistic); Map<String, String> metricLabels = getConventionTags(id).stream() .collect(Collectors.toMap(Tag::getKey, Tag::getValue)); return TimeSeries.newBuilder() .setMetric(Metric.newBuilder() .setType(metricType) .putAllLabels(metricLabels) .build()) .setResource(MonitoredResource.newBuilder() .setType(RESOURCE_TYPE) .putLabels("project_id", config.projectId()) .build()) .setMetricKind(MetricDescriptor.MetricKind.GAUGE) // https://cloud.google.com/monitoring/api/v3/metrics-details#metric-kinds .setValueType(valueType) .addPoints(Point.newBuilder() .setInterval(interval) .setValue(typedValue) .build()) .build(); }
/** * <pre> * The associated metric. A fully-specified metric used to identify the time * series. * </pre> * * <code>optional .google.api.Metric metric = 1;</code> */ public Builder mergeMetric(com.google.api.Metric value) { if (metricBuilder_ == null) { if (metric_ != null) { metric_ = com.google.api.Metric.newBuilder(metric_).mergeFrom(value).buildPartial(); } else { metric_ = value; } onChanged(); } else { metricBuilder_.mergeFrom(value); } return this; } /**
public Builder mergeFrom( com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException { com.google.api.Metric parsedMessage = null; try { parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); } catch (com.google.protobuf.InvalidProtocolBufferException e) { parsedMessage = (com.google.api.Metric) e.getUnfinishedMessage(); throw e.unwrapIOException(); } finally { if (parsedMessage != null) { mergeFrom(parsedMessage); } } return this; } private int bitField0_;
@VisibleForTesting static Metric createMetric( io.opencensus.metrics.export.MetricDescriptor metricDescriptor, List<LabelValue> labelValues, String domain) { Metric.Builder builder = Metric.newBuilder(); builder.setType(generateType(metricDescriptor.getName(), domain)); Map<String, String> stringTagMap = Maps.newHashMap(); List<LabelKey> labelKeys = metricDescriptor.getLabelKeys(); for (int i = 0; i < labelValues.size(); i++) { String value = labelValues.get(i).getValue(); if (value == null) { continue; } stringTagMap.put(labelKeys.get(i).getKey(), value); } stringTagMap.put(OPENCENSUS_TASK, OPENCENSUS_TASK_VALUE_DEFAULT); builder.putAllLabels(stringTagMap); return builder.build(); }
/** * <pre> * The associated metric. A fully-specified metric used to identify the time * series. * </pre> * * <code>optional .google.api.Metric metric = 1;</code> */ public Builder setMetric( com.google.api.Metric.Builder builderForValue) { if (metricBuilder_ == null) { metric_ = builderForValue.build(); onChanged(); } else { metricBuilder_.setMessage(builderForValue.build()); } return this; } /**
public static Builder newBuilder(com.google.api.Metric prototype) { return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype); } public Builder toBuilder() {
public Builder mergeFrom(com.google.protobuf.Message other) { if (other instanceof com.google.api.Metric) { return mergeFrom((com.google.api.Metric)other); } else { super.mergeFrom(other); return this; } }
public com.google.api.Metric build() { com.google.api.Metric result = buildPartial(); if (!result.isInitialized()) { throw newUninitializedMessageException(result); } return result; }
@java.lang.Override protected Builder newBuilderForType( com.google.protobuf.GeneratedMessageV3.BuilderParent parent) { Builder builder = new Builder(parent); return builder; } /**
@Test public void createMetric() { assertThat( StackdriverExportUtils.createMetric( METRIC_DESCRIPTOR, LABEL_VALUE, CUSTOM_OPENCENSUS_DOMAIN)) .isEqualTo( Metric.newBuilder() .setType("custom.googleapis.com/opencensus/" + METRIC_NAME) .putLabels("KEY1", "VALUE1") .putLabels(StackdriverExportUtils.OPENCENSUS_TASK, DEFAULT_TASK_VALUE) .build()); }
@Test public void createMetric_EmptyLabel() { assertThat( StackdriverExportUtils.createMetric( METRIC_DESCRIPTOR_2, EMPTY_LABEL_VALUE, CUSTOM_OPENCENSUS_DOMAIN)) .isEqualTo( Metric.newBuilder() .setType("custom.googleapis.com/opencensus/" + METRIC_NAME) .putLabels(StackdriverExportUtils.OPENCENSUS_TASK, DEFAULT_TASK_VALUE) .build()); }
@Test public void createMetric_WithExternalMetricDomain() { String prometheusDomain = "external.googleapis.com/prometheus/"; assertThat( StackdriverExportUtils.createMetric(METRIC_DESCRIPTOR, LABEL_VALUE, prometheusDomain)) .isEqualTo( Metric.newBuilder() .setType(prometheusDomain + METRIC_NAME) .putLabels("KEY1", "VALUE1") .putLabels(StackdriverExportUtils.OPENCENSUS_TASK, DEFAULT_TASK_VALUE) .build()); }
.setType("custom.googleapis.com/my_metric") .putAllLabels(metricLabels) .build();
metricLabels.put("store_id", "Pittsburg"); Metric metric = Metric.newBuilder() .setType("custom.googleapis.com/stores/daily_sales") .putAllLabels(metricLabels) .build();
/** * * * <pre> * The associated metric. A fully-specified metric used to identify the time * series. * </pre> * * <code>.google.api.Metric metric = 1;</code> */ public Builder mergeMetric(com.google.api.Metric value) { if (metricBuilder_ == null) { if (metric_ != null) { metric_ = com.google.api.Metric.newBuilder(metric_).mergeFrom(value).buildPartial(); } else { metric_ = value; } onChanged(); } else { metricBuilder_.mergeFrom(value); } return this; } /**