Skip to content
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 @@ -30,7 +30,7 @@
* latest Metrics2 collection interval. Metrics are not transactionally coordinated across client
* replacement or RegionServers and never feed HA decisions.
* <p>
* {@code haGroup} is the only source-specific tag. Monitoring systems must supply cluster,
* {@code ha_group} is the only source-specific tag. Monitoring systems must supply cluster,
* environment, host, and RegionServer identity as external scrape-target labels; role is mutable
* and is represented by the state gauges rather than a tag.
* <p>
Expand Down Expand Up @@ -61,9 +61,6 @@ public interface HAGroupStoreMetricsSource extends BaseSource {
// CLI invocations can create an incidental bean under the same context.
String METRICS_JMX_CONTEXT = "RegionServer,sub=" + METRICS_NAME;

String HA_GROUP_TAG_NAME = "haGroup";
String HA_GROUP_TAG_DESC = "HA group name";

String LOCAL_CACHE_HEALTH_STATUS = "haGroupStoreLocalCacheHealthStatus";
String LOCAL_CACHE_HEALTH_STATUS_DESC =
"Local HAGroupStore cache health status: 0 healthy, non-zero unhealthy";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
*/
package org.apache.phoenix.jdbc.metrics;

import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_DESC;
import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;

import java.util.concurrent.TimeUnit;
import javax.management.ObjectName;
import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
Expand Down Expand Up @@ -58,10 +61,10 @@ public HAGroupStoreMetricsSourceImpl(String haGroupName) {
metricsJmxContext + ",haGroup=" + ObjectName.quote(haGroupName));
getMetricsRegistry().tag(Interns.info(HA_GROUP_TAG_NAME, HA_GROUP_TAG_DESC), haGroupName);

localCacheHealthStatus = getMetricsRegistry().newGauge(LOCAL_CACHE_HEALTH_STATUS,
LOCAL_CACHE_HEALTH_STATUS_DESC, 1L);
peerVisibilityStatus = getMetricsRegistry().newGauge(PEER_VISIBILITY_STATUS,
PEER_VISIBILITY_STATUS_DESC, 1L);
localCacheHealthStatus =
getMetricsRegistry().newGauge(LOCAL_CACHE_HEALTH_STATUS, LOCAL_CACHE_HEALTH_STATUS_DESC, 1L);
peerVisibilityStatus =
getMetricsRegistry().newGauge(PEER_VISIBILITY_STATUS, PEER_VISIBILITY_STATUS_DESC, 1L);
degradedStandbyActive =
getMetricsRegistry().newGauge(DEGRADED_STANDBY_ACTIVE, DEGRADED_STANDBY_ACTIVE_DESC, 0L);
currentLocalState = getMetricsRegistry().newGauge(CURRENT_LOCAL_STATE, CURRENT_LOCAL_STATE_DESC,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.phoenix.metrics;

/**
* Shared Hadoop Metrics2 constant definitions used across Phoenix metric sources.
* <p>
* Holds the {@code ha_group} tag registered by the per-HA-group sources (HAGroupStore and the
* replication log sources) so their series can be sliced per HA group downstream. Lives in this
* module-neutral package so both {@code phoenix-core-client} and {@code phoenix-core-server}
* sources can reference it.
*/
public final class MetricConstants {

/** Metrics2 tag name carrying the HA group name. */
public static final String HA_GROUP_TAG_NAME = "ha_group";

/** Description for the {@link #HA_GROUP_TAG_NAME} tag. */
public static final String HA_GROUP_TAG_DESC = "HA group name";

private MetricConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
package org.apache.phoenix.replication.metrics;

import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_DESC;
import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;

import org.apache.hadoop.metrics2.lib.Interns;

/** Implementation of metrics source for ReplicationLogDiscoveryForwarder operations. */
public class MetricsReplicationLogDiscoveryForwarderImpl
extends MetricsReplicationLogDiscoveryImpl {
Expand All @@ -33,5 +38,6 @@ public MetricsReplicationLogDiscoveryForwarderImpl(final String haGroupName) {
MetricsReplicationLogDiscoveryForwarderImpl.METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName);
super.groupMetricsContext =
MetricsReplicationLogDiscoveryForwarderImpl.METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName;
getMetricsRegistry().tag(Interns.info(HA_GROUP_TAG_NAME, HA_GROUP_TAG_DESC), haGroupName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/
package org.apache.phoenix.replication.metrics;

import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_DESC;
import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;

import org.apache.hadoop.metrics2.lib.Interns;
import org.apache.hadoop.metrics2.lib.MutableGaugeLong;

/** Implementation of metrics source for ReplicationLogDiscoveryReplay operations. */
Expand All @@ -35,6 +39,7 @@ public MetricsReplicationLogDiscoveryReplayImpl(final String haGroupName) {
MetricsReplicationLogDiscoveryReplayImpl.METRICS_DESCRIPTION,
MetricsReplicationLogDiscoveryImpl.METRICS_CONTEXT,
MetricsReplicationLogDiscoveryReplayImpl.METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName);
getMetricsRegistry().tag(Interns.info(HA_GROUP_TAG_NAME, HA_GROUP_TAG_DESC), haGroupName);
consistencyPoint = getMetricsRegistry().newGauge(CONSISTENCY_POINT, CONSISTENCY_POINT_DESC, 0L);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
*/
package org.apache.phoenix.replication.metrics;

import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_DESC;
import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;

import java.lang.reflect.Field;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
import org.apache.hadoop.hbase.metrics.Snapshot;
import org.apache.hadoop.hbase.metrics.impl.HistogramImpl;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.metrics2.lib.Interns;
import org.apache.hadoop.metrics2.lib.MutableFastCounter;
import org.apache.hadoop.metrics2.lib.MutableHistogram;
import org.apache.hadoop.metrics2.lib.MutableSizeHistogram;
Expand Down Expand Up @@ -52,6 +56,7 @@ public MetricsReplicationLogGroupSourceImpl(String metricsName, String metricsDe
String metricsContext, String metricsJmxContext, String haGroupName) {
super(metricsName, metricsDescription, metricsContext,
metricsJmxContext + ",haGroup=" + haGroupName);
getMetricsRegistry().tag(Interns.info(HA_GROUP_TAG_NAME, HA_GROUP_TAG_DESC), haGroupName);
rotationCount = getMetricsRegistry().newCounter(ROTATION_COUNT, ROTATION_COUNT_DESC, 0L);
rotationFailuresCount =
getMetricsRegistry().newCounter(ROTATION_FAILURES, ROTATION_FAILURES_DESC, 0L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
*/
package org.apache.phoenix.replication.metrics;

import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_DESC;
import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;

import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.metrics2.lib.Interns;
import org.apache.hadoop.metrics2.lib.MutableFastCounter;
import org.apache.hadoop.metrics2.lib.MutableHistogram;

Expand All @@ -38,6 +42,7 @@ public MetricsReplicationLogProcessorImpl(final String haGroupName) {
this(METRICS_NAME, METRICS_DESCRIPTION, METRICS_CONTEXT,
METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName);
groupMetricsContext = METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName;
getMetricsRegistry().tag(Interns.info(HA_GROUP_TAG_NAME, HA_GROUP_TAG_DESC), haGroupName);
}

public MetricsReplicationLogProcessorImpl(String metricsName, String metricsDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
package org.apache.phoenix.replication.metrics;

import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_DESC;
import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;

import org.apache.hadoop.metrics2.lib.Interns;

public class MetricsReplicationLogTrackerForwarderImpl extends MetricsReplicationLogTrackerImpl {

private static final String METRICS_NAME = "ReplicationLogTrackerForwarder";
Expand All @@ -31,6 +36,7 @@ public MetricsReplicationLogTrackerForwarderImpl(final String haGroupName) {
MetricsReplicationLogTrackerForwarderImpl.METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName);
super.groupMetricsContext =
MetricsReplicationLogTrackerForwarderImpl.METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName;
getMetricsRegistry().tag(Interns.info(HA_GROUP_TAG_NAME, HA_GROUP_TAG_DESC), haGroupName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
package org.apache.phoenix.replication.metrics;

import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_DESC;
import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;

import org.apache.hadoop.metrics2.lib.Interns;

public class MetricsReplicationLogTrackerReplayImpl extends MetricsReplicationLogTrackerImpl {

private static final String METRICS_NAME = "ReplicationLogReplayFileTracker";
Expand All @@ -31,6 +36,7 @@ public MetricsReplicationLogTrackerReplayImpl(final String haGroupName) {
MetricsReplicationLogTrackerReplayImpl.METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName);
super.groupMetricsContext =
MetricsReplicationLogTrackerReplayImpl.METRICS_JMX_CONTEXT + ",haGroup=" + haGroupName;
getMetricsRegistry().tag(Interns.info(HA_GROUP_TAG_NAME, HA_GROUP_TAG_DESC), haGroupName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.CURRENT_PEER_STATE;
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.DEGRADED_STANDBY_ACTIVE;
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.DEGRADED_STANDBY_PRESENTED_COUNT;
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.HA_GROUP_TAG_NAME;
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.INVALID_TRANSITION_REJECTED_COUNT;
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.LOCAL_CACHE_HEALTH_STATUS;
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.LOCAL_ZK_CONNECTION_LOST_COUNT;
Expand All @@ -31,6 +30,7 @@
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.SUBSCRIBER_NOTIFY_TIME_MS;
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.SUBSCRIBER_NOTIFY_TIME_MS_EXPORTED_BASE;
import static org.apache.phoenix.jdbc.metrics.HAGroupStoreMetricsSource.SYSTEM_TABLE_SYNC_FAILED_COUNT;
import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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.phoenix.replication.metrics;

import static org.apache.phoenix.metrics.MetricConstants.HA_GROUP_TAG_NAME;
import static org.junit.Assert.assertEquals;

import org.apache.hadoop.hbase.metrics.BaseSourceImpl;
import org.junit.Test;

/**
* Verifies that every per-HA-group replication metrics source registers the {@code haGroup}
* Metrics2 tag carrying the raw (unquoted, case-preserved) HA group name, matching the existing
* HAGroupStore metrics source. This is the tag the JMX-to-Argus collector promotes so replication
* metrics can be sliced per HA group.
*/
public class MetricsReplicationLogSourceHaGroupTagTest {

private static void assertHaGroupTagged(BaseSourceImpl source, String haGroupName) {
assertEquals(haGroupName, source.getMetricsRegistry().getTag(HA_GROUP_TAG_NAME).value());
}

@Test
public void testLogGroupSourceTagsHaGroup() {
String haGroupName = "testHaGroup-" + System.nanoTime();
MetricsReplicationLogGroupSourceImpl source =
new MetricsReplicationLogGroupSourceImpl(haGroupName);
try {
assertHaGroupTagged(source, haGroupName);
} finally {
source.close();
}
}

@Test
public void testLogProcessorSourceTagsHaGroup() {
String haGroupName = "testHaGroup-" + System.nanoTime();
MetricsReplicationLogProcessorImpl source = new MetricsReplicationLogProcessorImpl(haGroupName);
try {
assertHaGroupTagged(source, haGroupName);
} finally {
source.close();
}
}

@Test
public void testDiscoveryReplaySourceTagsHaGroup() {
String haGroupName = "testHaGroup-" + System.nanoTime();
MetricsReplicationLogDiscoveryReplayImpl source =
new MetricsReplicationLogDiscoveryReplayImpl(haGroupName);
try {
assertHaGroupTagged(source, haGroupName);
} finally {
source.close();
}
}

@Test
public void testDiscoveryForwarderSourceTagsHaGroup() {
String haGroupName = "testHaGroup-" + System.nanoTime();
MetricsReplicationLogDiscoveryForwarderImpl source =
new MetricsReplicationLogDiscoveryForwarderImpl(haGroupName);
try {
assertHaGroupTagged(source, haGroupName);
} finally {
source.close();
}
}

@Test
public void testTrackerReplaySourceTagsHaGroup() {
String haGroupName = "testHaGroup-" + System.nanoTime();
MetricsReplicationLogTrackerReplayImpl source =
new MetricsReplicationLogTrackerReplayImpl(haGroupName);
try {
assertHaGroupTagged(source, haGroupName);
} finally {
source.close();
}
}

@Test
public void testTrackerForwarderSourceTagsHaGroup() {
String haGroupName = "testHaGroup-" + System.nanoTime();
MetricsReplicationLogTrackerForwarderImpl source =
new MetricsReplicationLogTrackerForwarderImpl(haGroupName);
try {
assertHaGroupTagged(source, haGroupName);
} finally {
source.close();
}
}
}