Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tombstoned metric to JMX #3166

Open
wants to merge 3 commits into
base: 7.7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class MetricsContainer {
public static final String METRIC_NAME_API_FAILURE_COUNT = "api-failure-count";
public static final String METRIC_NAME_REGISTERED_COUNT = "registered-count";
public static final String METRIC_NAME_DELETED_COUNT = "deleted-count";
public static final String METRIC_NAME_TOMBSTONED_COUNT = "tombstoned-count";
public static final String METRIC_NAME_AVRO_SCHEMAS_CREATED = "avro-schemas-created";
public static final String METRIC_NAME_AVRO_SCHEMAS_DELETED = "avro-schemas-deleted";
public static final String METRIC_NAME_JSON_SCHEMAS_CREATED = "json-schemas-created";
Expand All @@ -73,6 +74,7 @@ public class MetricsContainer {

private final SchemaRegistryMetric schemasCreated;
private final SchemaRegistryMetric schemasDeleted;
private final SchemaRegistryMetric schemasTombstoned;
private final SchemaRegistryMetric customSchemaProviders;
private final SchemaRegistryMetric apiCallsSuccess;
private final SchemaRegistryMetric apiCallsFailure;
Expand Down Expand Up @@ -127,6 +129,9 @@ public MetricsContainer(SchemaRegistryConfig config, String kafkaClusterId) {
new CumulativeCount());
this.schemasDeleted = createMetric(METRIC_NAME_DELETED_COUNT, "Number of deleted schemas",
new CumulativeCount());
this.schemasTombstoned = createMetric(METRIC_NAME_TOMBSTONED_COUNT,
"Number of tombstoned schemas",
new CumulativeCount());

this.avroSchemasCreated = createMetric(METRIC_NAME_AVRO_SCHEMAS_CREATED,
"Number of registered Avro schemas", new CumulativeCount());
Expand Down Expand Up @@ -216,6 +221,10 @@ public SchemaRegistryMetric getSchemasDeleted(String type) {
return getSchemaTypeMetric(type, false);
}

public SchemaRegistryMetric getSchemasTombstoned() {
return schemasTombstoned;
}

private SchemaRegistryMetric getSchemaTypeMetric(String type, boolean isRegister) {
switch (type) {
case AvroSchema.TYPE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private void handleSchemaUpdate(SchemaKey schemaKey,
}
} else {
lookupCache.schemaTombstoned(schemaKey, oldSchemaValue);
updateMetrics(metricsContainer.getSchemasTombstoned(), null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static io.confluent.kafka.schemaregistry.metrics.MetricsContainer.METRIC_NAME_DELETED_COUNT;
import static io.confluent.kafka.schemaregistry.metrics.MetricsContainer.METRIC_NAME_MASTER_SLAVE_ROLE;
import static io.confluent.kafka.schemaregistry.metrics.MetricsContainer.METRIC_NAME_REGISTERED_COUNT;
import static io.confluent.kafka.schemaregistry.metrics.MetricsContainer.METRIC_NAME_TOMBSTONED_COUNT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -63,6 +64,8 @@ public void testSchemaCreatedCount() throws Exception {
new ObjectName("kafka.schema.registry:type=" + METRIC_NAME_AVRO_SCHEMAS_CREATED);
ObjectName schemasDeleted =
new ObjectName("kafka.schema.registry:type=" + METRIC_NAME_DELETED_COUNT);
ObjectName schemasTombstoned =
new ObjectName("kafka.schema.registry:type=" + METRIC_NAME_TOMBSTONED_COUNT);
ObjectName avroDeleted =
new ObjectName("kafka.schema.registry:type=" + METRIC_NAME_AVRO_SCHEMAS_DELETED);

Expand Down Expand Up @@ -90,9 +93,16 @@ public void testSchemaCreatedCount() throws Exception {
subject, i.toString()));
}

// Tombstoning schemas should not modify create count.
for (Integer i = 1; i < schemaIdCounter; i++) {
assertEquals(i, service.deleteSchemaVersion(RestService.DEFAULT_REQUEST_PROPERTIES,
subject, i.toString(), true));
}

assertEquals((double) schemaCount, mBeanServer.getAttribute(schemasCreated, METRIC_NAME_REGISTERED_COUNT));
assertEquals((double) schemaCount, mBeanServer.getAttribute(avroCreated, METRIC_NAME_AVRO_SCHEMAS_CREATED));
assertEquals((double) schemaCount, mBeanServer.getAttribute(schemasDeleted, METRIC_NAME_DELETED_COUNT));
assertEquals((double) schemaCount, mBeanServer.getAttribute(schemasTombstoned, METRIC_NAME_TOMBSTONED_COUNT));
assertEquals((double) schemaCount, mBeanServer.getAttribute(avroDeleted, METRIC_NAME_AVRO_SCHEMAS_DELETED));
}

Expand Down