Use DisabledMetricMaker for InMemoryModule and RebuildNotedb
Most unit test code will not be worrying about metrics so pass in a dummy implmentation that discards recorded values. Rebuilding notedb on the command line pgm does not require metrics. This also applies to other batch programs. Change-Id: I2703c4e8a3fb9e31587c0ccf6d1f7c4083a4b3fe
This commit is contained in:
@@ -20,6 +20,8 @@ import com.google.common.cache.Cache;
|
|||||||
import com.google.gerrit.extensions.config.FactoryModule;
|
import com.google.gerrit.extensions.config.FactoryModule;
|
||||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||||
import com.google.gerrit.extensions.registration.DynamicSet;
|
import com.google.gerrit.extensions.registration.DynamicSet;
|
||||||
|
import com.google.gerrit.metrics.DisabledMetricMaker;
|
||||||
|
import com.google.gerrit.metrics.MetricMaker;
|
||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||||
import com.google.gerrit.rules.PrologModule;
|
import com.google.gerrit.rules.PrologModule;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
@@ -89,6 +91,7 @@ public class BatchProgramModule extends FactoryModule {
|
|||||||
install(reviewDbModule);
|
install(reviewDbModule);
|
||||||
install(new DiffExecutorModule());
|
install(new DiffExecutorModule());
|
||||||
install(PatchListCacheImpl.module());
|
install(PatchListCacheImpl.module());
|
||||||
|
bind(MetricMaker.class).to(DisabledMetricMaker.class);
|
||||||
|
|
||||||
// Plugins are not loaded and we're just running through each change
|
// Plugins are not loaded and we're just running through each change
|
||||||
// once, so don't worry about cache removal.
|
// once, so don't worry about cache removal.
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
// Copyright (C) 2015 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// Licensed 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 com.google.gerrit.metrics;
|
||||||
|
|
||||||
|
import com.google.gerrit.extensions.registration.RegistrationHandle;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/** Exports no metrics, useful for running batch programs. */
|
||||||
|
public class DisabledMetricMaker extends MetricMaker {
|
||||||
|
@Override
|
||||||
|
public Counter0 newCounter(String name, Description desc) {
|
||||||
|
return new Counter0() {
|
||||||
|
@Override public void incrementBy(long value) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <F1> Counter1<F1> newCounter(String name, Description desc,
|
||||||
|
Field<F1> field1) {
|
||||||
|
return new Counter1<F1>() {
|
||||||
|
@Override public void incrementBy(F1 field1, long value) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <F1, F2> Counter2<F1, F2> newCounter(String name, Description desc,
|
||||||
|
Field<F1> field1, Field<F2> field2) {
|
||||||
|
return new Counter2<F1, F2>() {
|
||||||
|
@Override public void incrementBy(F1 field1, F2 field2, long value) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <F1, F2, F3> Counter3<F1, F2, F3> newCounter(String name,
|
||||||
|
Description desc, Field<F1> field1, Field<F2> field2, Field<F3> field3) {
|
||||||
|
return new Counter3<F1, F2, F3>() {
|
||||||
|
@Override public void incrementBy(F1 field1, F2 field2, F3 field3, long value) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Timer0 newTimer(String name, Description desc) {
|
||||||
|
return new Timer0() {
|
||||||
|
@Override public void record(long value, TimeUnit unit) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <F1> Timer1<F1> newTimer(String name, Description desc,
|
||||||
|
Field<F1> field1) {
|
||||||
|
return new Timer1<F1>() {
|
||||||
|
@Override public void record(F1 field1, long value, TimeUnit unit) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <F1, F2> Timer2<F1, F2> newTimer(String name, Description desc,
|
||||||
|
Field<F1> field1, Field<F2> field2) {
|
||||||
|
return new Timer2<F1, F2>() {
|
||||||
|
@Override public void record(F1 field1, F2 field2, long value, TimeUnit unit) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <F1, F2, F3> Timer3<F1, F2, F3> newTimer(String name,
|
||||||
|
Description desc, Field<F1> field1, Field<F2> field2, Field<F3> field3) {
|
||||||
|
return new Timer3<F1, F2, F3>() {
|
||||||
|
@Override public void record(F1 field1, F2 field2, F3 field3, long value, TimeUnit unit) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <V> CallbackMetric0<V> newCallbackMetric(String name,
|
||||||
|
Class<V> valueClass, Description desc) {
|
||||||
|
return new CallbackMetric0<V>() {
|
||||||
|
@Override public void set(V value) {}
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RegistrationHandle newTrigger(Set<CallbackMetric<?>> metrics,
|
||||||
|
Runnable trigger) {
|
||||||
|
return new RegistrationHandle() {
|
||||||
|
@Override public void remove() {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,7 +22,8 @@ import com.google.gerrit.common.ChangeHooks;
|
|||||||
import com.google.gerrit.common.DisabledChangeHooks;
|
import com.google.gerrit.common.DisabledChangeHooks;
|
||||||
import com.google.gerrit.extensions.config.FactoryModule;
|
import com.google.gerrit.extensions.config.FactoryModule;
|
||||||
import com.google.gerrit.gpg.GpgModule;
|
import com.google.gerrit.gpg.GpgModule;
|
||||||
import com.google.gerrit.metrics.dropwizard.DropWizardMetricMaker;
|
import com.google.gerrit.metrics.DisabledMetricMaker;
|
||||||
|
import com.google.gerrit.metrics.MetricMaker;
|
||||||
import com.google.gerrit.reviewdb.client.AuthType;
|
import com.google.gerrit.reviewdb.client.AuthType;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
import com.google.gerrit.server.GerritPersonIdent;
|
||||||
@@ -133,7 +134,7 @@ public class InMemoryModule extends FactoryModule {
|
|||||||
.toInstance(cfg);
|
.toInstance(cfg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
install(new DropWizardMetricMaker.Module());
|
bind(MetricMaker.class).to(DisabledMetricMaker.class);
|
||||||
install(cfgInjector.getInstance(GerritGlobalModule.class));
|
install(cfgInjector.getInstance(GerritGlobalModule.class));
|
||||||
install(new ChangeCacheImplModule(false));
|
install(new ChangeCacheImplModule(false));
|
||||||
factory(GarbageCollection.Factory.class);
|
factory(GarbageCollection.Factory.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user