-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHOENIX-3655 Global Phoenix Client Metrics for PQS
- Loading branch information
1 parent
da2796a
commit 1c82e03
Showing
10 changed files
with
537 additions
and
16 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
phoenix-core/src/it/java/org/apache/phoenix/monitoring/GlobalPhoenixMetricsTestSink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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.monitoring; | ||
|
||
import org.apache.commons.configuration.SubsetConfiguration; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.hadoop.metrics2.AbstractMetric; | ||
import org.apache.hadoop.metrics2.MetricsRecord; | ||
import org.apache.hadoop.metrics2.MetricsSink; | ||
import org.apache.phoenix.util.PhoenixRuntime; | ||
|
||
import java.util.Map; | ||
|
||
import static junit.framework.TestCase.assertTrue; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
public class GlobalPhoenixMetricsTestSink implements MetricsSink { | ||
|
||
public static final String PHOENIX_METRICS_RECORD_NAME = "PHOENIX"; | ||
// PhoenixMetricsIT tests verifies these metrics from this sink in a separate thread | ||
// GlobalPhoenixMetricsTestSink is invoked based on time defined in hadoop-metrics2.properties | ||
// This lock is to prevent concurrent access to metrics Iterable for these threads | ||
static Object lock = new Object(); | ||
static Iterable<AbstractMetric> metrics; | ||
|
||
@Override | ||
public void putMetrics(MetricsRecord metricsRecord) { | ||
if (metricsRecord.name().equals(PHOENIX_METRICS_RECORD_NAME)) { | ||
synchronized (GlobalPhoenixMetricsTestSink.lock) { | ||
GlobalPhoenixMetricsTestSink.metrics = metricsRecord.metrics(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void flush() { | ||
} | ||
|
||
@Override | ||
public void init(SubsetConfiguration subsetConfiguration) { | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
phoenix-core/src/it/java/org/apache/phoenix/monitoring/PhoenixMetricsDisabledIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.monitoring; | ||
|
||
import com.google.common.collect.Maps; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hbase.HBaseConfiguration; | ||
import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT; | ||
import org.apache.phoenix.jdbc.PhoenixDriver; | ||
import org.apache.phoenix.query.ConfigurationFactory; | ||
import org.apache.phoenix.query.QueryServices; | ||
import org.apache.phoenix.util.InstanceResolver; | ||
import org.apache.phoenix.util.PhoenixRuntime; | ||
import org.apache.phoenix.util.ReadOnlyProps; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import java.sql.DriverManager; | ||
import java.util.Map; | ||
|
||
import static org.apache.phoenix.monitoring.NoOpGlobalMetricImpl.NO_SAMPLES; | ||
import static org.apache.phoenix.monitoring.NoOpGlobalMetricImpl.NO_VALUE; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class PhoenixMetricsDisabledIT extends BaseUniqueNamesOwnClusterIT { | ||
|
||
@BeforeClass | ||
public static void doSetup() throws Exception { | ||
final Configuration conf = HBaseConfiguration.create(); | ||
conf.set(QueryServices.GLOBAL_METRICS_ENABLED, String.valueOf(false)); | ||
conf.set(QueryServices.RENEW_LEASE_ENABLED, String.valueOf(false)); | ||
// Clear the cached singletons so we can inject our own. | ||
InstanceResolver.clearSingletons(); | ||
// Make sure the ConnectionInfo doesn't try to pull a default Configuration | ||
InstanceResolver.getSingleton(ConfigurationFactory.class, new ConfigurationFactory() { | ||
@Override | ||
public Configuration getConfiguration() { | ||
return conf; | ||
} | ||
@Override | ||
public Configuration getConfiguration(Configuration confToClone) { | ||
Configuration copy = new Configuration(conf); | ||
copy.addResource(confToClone); | ||
return copy; | ||
} | ||
}); | ||
|
||
Map<String, String> props = Maps.newHashMapWithExpectedSize(1); | ||
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator())); | ||
|
||
DriverManager.registerDriver(PhoenixDriver.INSTANCE); | ||
} | ||
|
||
@Test | ||
public void testResetGlobalPhoenixMetrics() { | ||
for (GlobalMetric m : PhoenixRuntime.getGlobalPhoenixClientMetrics()) { | ||
assertThat(m, CoreMatchers.<GlobalMetric>instanceOf(NoOpGlobalMetricImpl.class)); | ||
assertEquals(NO_VALUE, m.getTotalSum()); | ||
assertEquals(NO_SAMPLES, m.getNumberOfSamples()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.