Skip to content
Permalink
Browse files
Add logging from monitoring interceptor, all tasks added to monitorin…
…g log
  • Loading branch information
dspavlov committed Jul 30, 2019
1 parent 7414f77 commit aeb9c40d53885727460ed7b3ecff2ce4a37a1fa7
Show file tree
Hide file tree
Showing 17 changed files with 275 additions and 107 deletions.

This file was deleted.

@@ -14,51 +14,50 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.ci.di;
package org.apache.ignite.ci.tcbot;

import com.google.common.base.Preconditions;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.internal.SingletonScope;
import com.google.inject.matcher.Matchers;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Provider;
import org.apache.ignite.Ignite;
import org.apache.ignite.ci.db.Ignite1Init;
import org.apache.ignite.ci.di.cache.GuavaCachedModule;
import org.apache.ignite.ci.issue.IssuesStorage;
import org.apache.ignite.ci.tcbot.conf.LocalFilesBasedConfig;
import org.apache.ignite.ci.tcbot.issue.IIssuesStorage;
import org.apache.ignite.ci.tcbot.trends.MasterTrendsService;
import org.apache.ignite.ci.tcbot.user.IUserStorage;
import org.apache.ignite.ci.tcbot.user.UserAndSessionsStorage;
import org.apache.ignite.tcbot.common.conf.IDataSourcesConfigSupplier;
import org.apache.ignite.tcbot.engine.TcBotEngineModule;
import org.apache.ignite.tcbot.engine.conf.ITcBotConfig;
import org.apache.ignite.tcbot.notify.TcBotNotificationsModule;
import org.apache.ignite.tcbot.persistence.scheduler.SchedulerModule;
import org.apache.ignite.githubignited.GitHubIgnitedModule;
import org.apache.ignite.jiraignited.JiraIgnitedModule;
import org.apache.ignite.ci.observer.BuildObserver;
import org.apache.ignite.ci.observer.ObserverTask;
import org.apache.ignite.ci.tcbot.TcBotBusinessServicesModule;
import org.apache.ignite.ci.tcbot.issue.IssueDetector;
import org.apache.ignite.tcbot.common.exeption.ServicesStartingException;
import org.apache.ignite.tcbot.persistence.TcBotPersistenceModule;
import org.apache.ignite.tcignited.TeamcityIgnitedModule;
import org.apache.ignite.tcbot.common.exeption.ExceptionUtil;
import org.apache.ignite.tcbot.engine.pool.TcUpdatePool;
import org.apache.ignite.ci.web.model.hist.VisasHistoryStorage;
import org.apache.ignite.tcbot.common.interceptor.AutoProfiling;
import org.apache.ignite.tcbot.common.interceptor.MonitoredTask;

/**
*
*/
public class IgniteTcBotModule extends AbstractModule {
public class TcBotWebAppModule extends AbstractModule {
/** Ignite future. */
private Future<Ignite> igniteFut;

/** {@inheritDoc} */
@Override protected void configure() {
install(new GuavaCachedModule());
configProfiling();
configTaskMonitor();

bind(Ignite.class).toProvider((Provider<Ignite>)() -> {
Preconditions.checkNotNull(igniteFut, "Ignite future is not yet initialized");

@@ -90,27 +89,13 @@ public class IgniteTcBotModule extends AbstractModule {

// common services
install(new TcBotEngineModule());
install(new TcBotBusinessServicesModule());
}

private void configProfiling() {
AutoProfilingInterceptor profilingInterceptor = new AutoProfilingInterceptor();

bindInterceptor(Matchers.any(),
Matchers.annotatedWith(AutoProfiling.class),
profilingInterceptor);

bind(AutoProfilingInterceptor.class).toInstance(profilingInterceptor);
}

private void configTaskMonitor() {
MonitoredTaskInterceptor profilingInterceptor = new MonitoredTaskInterceptor();

bindInterceptor(Matchers.any(),
Matchers.annotatedWith(MonitoredTask.class),
profilingInterceptor);

bind(MonitoredTaskInterceptor.class).toInstance(profilingInterceptor);
bind(ITcBotConfig.class).to(LocalFilesBasedConfig.class).in(new SingletonScope());
//todo remove duplication of instances for base and for overriden class
bind(IDataSourcesConfigSupplier.class).to(LocalFilesBasedConfig.class).in(new SingletonScope());
bind(IUserStorage.class).to(UserAndSessionsStorage.class).in(new SingletonScope());
bind(IIssuesStorage.class).to(IssuesStorage.class).in(new SingletonScope());
bind(MasterTrendsService.class).in(new SingletonScope());
bind(ITcBotBgAuth.class).to(TcBotBgAuthImpl.class).in(new SingletonScope());
}

public void setIgniteFut(Future<Ignite> igniteFut) {
@@ -27,7 +27,8 @@
import javax.servlet.ServletContextListener;
import org.apache.ignite.Ignite;
import org.apache.ignite.ci.db.TcHelperDb;
import org.apache.ignite.ci.di.IgniteTcBotModule;
import org.apache.ignite.ci.tcbot.TcBotWebAppModule;
import org.apache.ignite.tcbot.common.interceptor.MonitoredTaskInterceptor;
import org.apache.ignite.tcbot.engine.pool.TcUpdatePool;
import org.apache.ignite.tcbot.persistence.scheduler.IScheduler;
import org.apache.ignite.ci.observer.BuildObserver;
@@ -51,7 +52,7 @@ public static Injector getInjector(ServletContext ctx) {
/** {@inheritDoc} */
@Override public void contextInitialized(ServletContextEvent sctxEvt) {
initLoggerBridge();
IgniteTcBotModule igniteTcBotModule = new IgniteTcBotModule();
TcBotWebAppModule igniteTcBotModule = new TcBotWebAppModule();
Injector injectorPreCreated = Guice.createInjector(igniteTcBotModule);

Injector injector = igniteTcBotModule.startIgniteInit(injectorPreCreated);
@@ -106,6 +107,13 @@ private void initLoggerBridge() {
logger.error("Exception during shutdown: " + e.getMessage(), e);
}

try {
injector.getInstance(MonitoredTaskInterceptor.class).close();
}
catch (Exception e) {
e.printStackTrace();
}

try {
TcHelperDb.stop(injector.getInstance(Ignite.class));
}
@@ -21,8 +21,8 @@
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheMetrics;
import org.apache.ignite.cache.affinity.Affinity;
import org.apache.ignite.ci.di.AutoProfilingInterceptor;
import org.apache.ignite.ci.di.MonitoredTaskInterceptor;
import org.apache.ignite.tcbot.common.interceptor.AutoProfilingInterceptor;
import org.apache.ignite.tcbot.common.interceptor.MonitoredTaskInterceptor;
import org.apache.ignite.ci.web.CtxListener;

import javax.annotation.security.PermitAll;
@@ -26,6 +26,8 @@
import org.apache.ignite.ci.observer.BuildObserver;
import org.apache.ignite.ci.observer.ObserverTask;
import org.apache.ignite.ci.tcbot.ITcBotBgAuth;
import org.apache.ignite.ci.tcbot.TcBotWebAppModule;
import org.apache.ignite.tcbot.common.interceptor.MonitoredTaskInterceptor;
import org.apache.ignite.tcbot.engine.chain.BuildChainProcessor;
import org.apache.ignite.tcbot.engine.conf.ITcBotConfig;
import org.apache.ignite.tcbot.engine.pool.TcUpdatePool;
@@ -55,7 +57,7 @@ public void checkSingletons() {
}

public Injector getInjector() {
IgniteTcBotModule igniteTcBotModule = new IgniteTcBotModule();
TcBotWebAppModule igniteTcBotModule = new TcBotWebAppModule();
Ignite ignite = mock(Ignite.class);
when(ignite.getOrCreateCache(anyString())).thenReturn(Mockito.mock(IgniteCache.class));
when(ignite.getOrCreateCache(any(CacheConfiguration.class))).thenReturn(Mockito.mock(IgniteCache.class));
@@ -89,7 +91,7 @@ private <T> T validateInstanceCachedFor(Injector injector, Class<T> type) {

@Test
public void testMonitoring() {
IgniteTcBotModule igniteTcBotModule = new IgniteTcBotModule();
TcBotWebAppModule igniteTcBotModule = new TcBotWebAppModule();
final Injector injector = Guice.createInjector(igniteTcBotModule);
final MonitorTest instance = injector.getInstance(MonitorTest.class);

@@ -21,6 +21,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.ignite.tcbot.common.interceptor.GuavaCached;
import org.apache.ignite.tcbot.common.interceptor.GuavaCachedModule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
@@ -0,0 +1,36 @@
/*
* 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.ignite.tcbot.common;

import com.google.inject.AbstractModule;
import org.apache.ignite.tcbot.common.interceptor.AutoProfilingInterceptorModule;
import org.apache.ignite.tcbot.common.interceptor.GuavaCachedModule;
import org.apache.ignite.tcbot.common.interceptor.MonitoredTaskInterceptorModule;

/**
*
*/
public class TcBotCommonModule extends AbstractModule {
/** {@inheritDoc} */
@Override protected void configure() {
install(new MonitoredTaskInterceptorModule());

install(new AutoProfilingInterceptorModule());

install(new GuavaCachedModule());
}
}
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.ci.di;
package org.apache.ignite.tcbot.common.interceptor;

import com.google.common.base.Stopwatch;
import java.util.Collection;
@@ -0,0 +1,36 @@
/*
* 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.ignite.tcbot.common.interceptor;

import com.google.inject.AbstractModule;
import com.google.inject.matcher.Matchers;

public class AutoProfilingInterceptorModule extends AbstractModule {
@Override protected void configure() {
configProfiling();
}

private void configProfiling() {
AutoProfilingInterceptor profilingInterceptor = new AutoProfilingInterceptor();

bindInterceptor(Matchers.any(),
Matchers.annotatedWith(AutoProfiling.class),
profilingInterceptor);

bind(AutoProfilingInterceptor.class).toInstance(profilingInterceptor);
}
}
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ignite.ci.di.cache;
package org.apache.ignite.tcbot.common.interceptor;

import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
@@ -28,10 +28,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.ignite.tcbot.common.interceptor.GuavaCached;
import org.jetbrains.annotations.NotNull;

public class GuavaCachedInterceptor implements MethodInterceptor {
private final ConcurrentMap<String, Cache<List, Optional>> caches = new ConcurrentHashMap<>();
@@ -95,13 +94,12 @@ public class GuavaCachedInterceptor implements MethodInterceptor {
return optional.orElse(null);
}

@NotNull
@Nonnull
private String cacheId(MethodInvocation invocation) {
final Method invocationMtd = invocation.getMethod();
final String cls = invocationMtd.getDeclaringClass().getName();
final String mtd = invocationMtd.getName();

return cls + "." + mtd;
}

}
@@ -15,11 +15,10 @@
* limitations under the License.
*/

package org.apache.ignite.ci.di.cache;
package org.apache.ignite.tcbot.common.interceptor;

import com.google.inject.AbstractModule;
import com.google.inject.matcher.Matchers;
import org.apache.ignite.tcbot.common.interceptor.GuavaCached;

/**
*
@@ -37,4 +37,9 @@
* Array of Argument indexes (0-based) to be used to extend name.
*/
int[] nameExtArgsIndexes() default {};

/**
* Add log record to monitoring.txt log
*/
boolean log() default true;
}

0 comments on commit aeb9c40

Please sign in to comment.