/** * * * <pre> * The new [custom metric](/monitoring/custom-metrics) * descriptor. * </pre> * * <code>.google.api.MetricDescriptor metric_descriptor = 2;</code> */ public Builder mergeMetricDescriptor(com.google.api.MetricDescriptor value) { if (metricDescriptorBuilder_ == null) { if (metricDescriptor_ != null) { metricDescriptor_ = com.google.api.MetricDescriptor.newBuilder(metricDescriptor_) .mergeFrom(value) .buildPartial(); } else { metricDescriptor_ = value; } onChanged(); } else { metricDescriptorBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * The new [custom metric](/monitoring/custom-metrics) * descriptor. * </pre> * * <code>.google.api.MetricDescriptor metric_descriptor = 2;</code> */ public com.google.api.MetricDescriptor getMetricDescriptor() { return metricDescriptor_ == null ? com.google.api.MetricDescriptor.getDefaultInstance() : metricDescriptor_; } /**
@Test public void createMetricDescriptor_cumulative() { MetricDescriptor metricDescriptor = StackdriverExportUtils.createMetricDescriptor( METRIC_DESCRIPTOR_2, PROJECT_ID, CUSTOM_OPENCENSUS_DOMAIN, DEFAULT_DISPLAY_NAME_PREFIX); assertThat(metricDescriptor.getName()) .isEqualTo( "projects/" + PROJECT_ID + "/metricDescriptors/custom.googleapis.com/opencensus/" + METRIC_NAME); assertThat(metricDescriptor.getDescription()).isEqualTo(METRIC_DESCRIPTION); assertThat(metricDescriptor.getDisplayName()).isEqualTo("OpenCensus/" + METRIC_NAME); assertThat(metricDescriptor.getType()) .isEqualTo("custom.googleapis.com/opencensus/" + METRIC_NAME); assertThat(metricDescriptor.getUnit()).isEqualTo("1"); assertThat(metricDescriptor.getMetricKind()).isEqualTo(MetricKind.CUMULATIVE); assertThat(metricDescriptor.getValueType()).isEqualTo(MetricDescriptor.ValueType.INT64); assertThat(metricDescriptor.getLabelsList()) .containsExactly( LabelDescriptor.newBuilder() .setKey(StackdriverExportUtils.OPENCENSUS_TASK) .setDescription(StackdriverExportUtils.OPENCENSUS_TASK_DESCRIPTION) .setValueType(ValueType.STRING) .build()); }
MessageLocationContext.create(metric, MetricDescriptor.NAME_FIELD_NUMBER), "metric name", metric.getName()); metric.getDisplayName()); metric.getDescription()); String.format("'%s' metric", metric.getName()), metric.getLabelsList()); if (metric.getMetricKind() == MetricKind.METRIC_KIND_UNSPECIFIED) { error( MessageLocationContext.create(metric, MetricDescriptor.NAME_FIELD_NUMBER), "The metric kind of the '%s' metric is not specified. " + "Allowed values are GAUGE, DELTA and CUMULATIVE.", metric.getName()); if (metric.getValueType() == ValueType.VALUE_TYPE_UNSPECIFIED) { error( MessageLocationContext.create(metric, MetricDescriptor.NAME_FIELD_NUMBER), "The metric value type of the '%s' metric is not specified. " + "Allowed values are BOOL, INT64, DOUBLE, STRING, DISTRIBUTION and MONEY.", metric.getName()); if ((metric.getValueType() == ValueType.BOOL || metric.getValueType() == ValueType.STRING) && metric.getMetricKind() != MetricKind.GAUGE) { error( MessageLocationContext.create(metric, MetricDescriptor.NAME_FIELD_NUMBER),
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + NAME_FIELD_NUMBER; hash = (53 * hash) + getName().hashCode(); hash = (37 * hash) + TYPE_FIELD_NUMBER; hash = (53 * hash) + getType().hashCode(); if (getLabelsCount() > 0) { hash = (37 * hash) + LABELS_FIELD_NUMBER; hash = (53 * hash) + getLabelsList().hashCode(); } hash = (37 * hash) + METRIC_KIND_FIELD_NUMBER; hash = (53 * hash) + metricKind_; hash = (37 * hash) + VALUE_TYPE_FIELD_NUMBER; hash = (53 * hash) + valueType_; hash = (37 * hash) + UNIT_FIELD_NUMBER; hash = (53 * hash) + getUnit().hashCode(); hash = (37 * hash) + DESCRIPTION_FIELD_NUMBER; hash = (53 * hash) + getDescription().hashCode(); hash = (37 * hash) + DISPLAY_NAME_FIELD_NUMBER; hash = (53 * hash) + getDisplayName().hashCode(); hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
public Builder mergeFrom(com.google.api.MetricDescriptor other) { if (other == com.google.api.MetricDescriptor.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); if (!other.getType().isEmpty()) { type_ = other.type_; onChanged(); setMetricKindValue(other.getMetricKindValue()); setValueTypeValue(other.getValueTypeValue()); if (!other.getUnit().isEmpty()) { unit_ = other.unit_; onChanged(); if (!other.getDescription().isEmpty()) { description_ = other.description_; onChanged(); if (!other.getDisplayName().isEmpty()) { displayName_ = other.displayName_; onChanged();
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.api.MetricDescriptor)) { return super.equals(obj); } com.google.api.MetricDescriptor other = (com.google.api.MetricDescriptor) obj; boolean result = true; result = result && getName() .equals(other.getName()); result = result && getType() .equals(other.getType()); result = result && getLabelsList() .equals(other.getLabelsList()); result = result && metricKind_ == other.metricKind_; result = result && valueType_ == other.valueType_; result = result && getUnit() .equals(other.getUnit()); result = result && getDescription() .equals(other.getDescription()); result = result && getDisplayName() .equals(other.getDisplayName()); return result; }
private void validateMetrics(List<MetricDescriptor> metricsList) { // - Metrics list cannot be longer than predefined limit. validateMaxListSize( ResolvedLocation.create(SimpleLocation.TOPLEVEL), "metrics list", metricsList, bounds.getMaxMetrics()); // - Metric name must be unique across merged lists. for (MetricDescriptor metric : metricsList) { if (metrics.containsKey(metric.getName())) { error( MessageLocationContext.create(metric, MetricDescriptor.NAME_FIELD_NUMBER), "The '%s' metric is already defined. The metric name must be unique.", metric.getName()); } metrics.put(metric.getName(), false); validateMetric(metric); } }
/** * Returns the first page of all metric descriptors. */ void listMetricDescriptors() throws IOException { // [START monitoring_list_descriptors] // Your Google Cloud Platform project ID String projectId = System.getProperty("projectId"); final MetricServiceClient client = MetricServiceClient.create(); ProjectName name = ProjectName.of(projectId); ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest .newBuilder() .setName(name.toString()) .build(); ListMetricDescriptorsPagedResponse response = client.listMetricDescriptors(request); System.out.println("Listing descriptors: "); for (MetricDescriptor d : response.iterateAll()) { System.out.println(d.getName() + " " + d.getDisplayName()); } // [END monitoring_list_descriptors] }
/** * <pre> * The resource name of the metric descriptor. Depending on the * implementation, the name typically includes: (1) the parent resource name * that defines the scope of the metric type or of its data; and (2) the * metric's URL-encoded type, which also appears in the `type` field of this * descriptor. For example, following is the resource name of a custom * metric within the GCP project `my-project-id`: * "projects/my-project-id/metricDescriptors/custom.googleapis.com%2Finvoice%2Fpaid%2Famount" * </pre> * * <code>string name = 1;</code> */ public Builder clearName() { name_ = getDefaultInstance().getName(); onChanged(); return this; } /**
private List<MetricDescriptor> parseMetrics( ServiceManagementExtension extension, VendorExtensionProtoConverter extensionConverter) { if (extension.getMetrics() == null) { return ImmutableList.of(); } try { String extensionJson = new ObjectMapper().writer().writeValueAsString(extension.getMetrics()); return extensionConverter.convertJsonArrayToProto( MetricDescriptor.getDefaultInstance(), new ObjectMapper().readTree(extensionJson), "metrics"); } catch (IOException ex) { diagCollector.addDiag( Diag.error( new SimpleLocation("metrics"), "Extension %s cannot be converted into proto type %s. Details: %s", "quota", MetricDescriptor.getDescriptor().getFullName(), ex.getMessage())); return ImmutableList.of(); } }
/** * <pre> * A concise name for the metric, which can be displayed in user interfaces. * Use sentence case without an ending period, for example "Request count". * </pre> * * <code>string display_name = 7;</code> */ public Builder clearDisplayName() { displayName_ = getDefaultInstance().getDisplayName(); onChanged(); return this; } /**
/** * <pre> * A detailed description of the metric, which can be used in documentation. * </pre> * * <code>string description = 6;</code> */ public Builder clearDescription() { description_ = getDefaultInstance().getDescription(); onChanged(); return this; } /**
/** * <pre> * The metric type, including its DNS name prefix. The type is not * URL-encoded. All user-defined custom metric types have the DNS name * `custom.googleapis.com`. Metric types should use a natural hierarchical * grouping. For example: * "custom.googleapis.com/invoice/paid/amount" * "appengine.googleapis.com/http/server/response_latencies" * </pre> * * <code>string type = 8;</code> */ public Builder clearType() { type_ = getDefaultInstance().getType(); onChanged(); return this; } /**
unit_ = getDefaultInstance().getUnit(); onChanged(); return this;
input.readMessage(com.google.api.MetricDescriptor.parser(), extensionRegistry)); break;
public static Builder newBuilder() { return DEFAULT_INSTANCE.toBuilder(); } public static Builder newBuilder(com.google.api.MetricDescriptor prototype) {
@java.lang.Override public boolean equals(final java.lang.Object obj) { if (obj == this) { return true; } if (!(obj instanceof com.google.monitoring.v3.CreateMetricDescriptorRequest)) { return super.equals(obj); } com.google.monitoring.v3.CreateMetricDescriptorRequest other = (com.google.monitoring.v3.CreateMetricDescriptorRequest) obj; boolean result = true; result = result && getName().equals(other.getName()); result = result && (hasMetricDescriptor() == other.hasMetricDescriptor()); if (hasMetricDescriptor()) { result = result && getMetricDescriptor().equals(other.getMetricDescriptor()); } result = result && unknownFields.equals(other.unknownFields); return result; }
public static final com.google.protobuf.Descriptors.EnumDescriptor getDescriptor() { return com.google.api.MetricDescriptor.getDescriptor().getEnumTypes().get(0); }