Shoothzj commented on code in PR #14723: URL: https://github.com/apache/pulsar/pull/14723#discussion_r886193946
########## pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/SchemaRegistryStats.java: ########## @@ -0,0 +1,125 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pulsar.broker.service.schema; + +import io.prometheus.client.CollectorRegistry; +import io.prometheus.client.Counter; +import io.prometheus.client.Summary; +import java.util.concurrent.atomic.AtomicBoolean; + +class SchemaRegistryStats implements AutoCloseable { + private static final String SCHEMA_ID = "schema"; + private static final double[] QUANTILES = {0.50, 0.75, 0.95, 0.99, 0.999, 0.9999, 1}; + private static final AtomicBoolean CLOSED = new AtomicBoolean(false); + + private final Counter getOpsFailedCounter; + private final Counter putOpsFailedCounter; + private final Counter deleteOpsFailedCounter; + + private final Counter compatibleCounter; + private final Counter incompatibleCounter; + + private final Summary deleteOpsLatency; + private final Summary getOpsLatency; + private final Summary putOpsLatency; + + private static volatile SchemaRegistryStats instance; + + static synchronized SchemaRegistryStats getInstance() { + if (null == instance) { + instance = new SchemaRegistryStats(); + } + + return instance; + } + + private SchemaRegistryStats() { + this.deleteOpsFailedCounter = Counter.build("pulsar_schema_del_ops_failed_count", "-") + .labelNames(SCHEMA_ID).create().register(); + this.getOpsFailedCounter = Counter.build("pulsar_schema_get_ops_failed_count", "-") + .labelNames(SCHEMA_ID).create().register(); + this.putOpsFailedCounter = Counter.build("pulsar_schema_put_ops_failed_count", "-") + .labelNames(SCHEMA_ID).create().register(); + + this.compatibleCounter = Counter.build("pulsar_schema_compatible_count", "-") + .labelNames(SCHEMA_ID).create().register(); + this.incompatibleCounter = Counter.build("pulsar_schema_incompatible_count", "-") + .labelNames(SCHEMA_ID).create().register(); + + this.deleteOpsLatency = this.buildSummary("pulsar_schema_del_ops_latency", "-"); + this.getOpsLatency = this.buildSummary("pulsar_schema_get_ops_latency", "-"); + this.putOpsLatency = this.buildSummary("pulsar_schema_put_ops_latency", "-"); + } + + private Summary buildSummary(String name, String help) { + Summary.Builder builder = Summary.build(name, help).labelNames(SCHEMA_ID); + + for (double quantile : QUANTILES) { + builder.quantile(quantile, 0.01D); + } + + return builder.create().register(); + } + + void recordDelFailed(String schemaId) { + this.deleteOpsFailedCounter.labels(schemaId).inc(); Review Comment: #15801 is fixing this @merlimat PTAL -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
