diff --git a/README.md b/README.md index 5ab9703d74a506405790ca6c51137efce05a8ed2..0ac610447c974f14641e474f16f8b566410b8e15 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ microservices, cloud native and container-based (Docker, K8s, Mesos) architectur Underlying technology is a distributed tracing system. [![Build Status](https://travis-ci.org/apache/incubator-skywalking.svg?branch=master)](https://travis-ci.org/apache/incubator-skywalking) -[![Coverage Status](https://coveralls.io/repos/github/apache/incubator-skywalking/badge.svg?branch=master&u=1)](https://coveralls.io/github/apache/incubator-skywalking?branch=master) +[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/AsfSkyWalking) [![Join the chat at https://gitter.im/sky-walking/Lobby](https://badges.gitter.im/openskywalking/Lobby.svg)](https://gitter.im/openskywalking/Lobby) [![OpenTracing-1.x Badge](https://img.shields.io/badge/OpenTracing--1.x-enabled-blue.svg)](http://opentracing.io) diff --git a/README_ZH.md b/README_ZH.md index e6c31b836e7cc27f3eb7aa753089a8a1fe77be40..6a274fc04f9b6679e8a3895d6ab49108f99e1add 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -7,7 +7,7 @@ Apache SkyWalking | [English](README.md) 其核心是个分布式追踪系统。 [![Build Status](https://travis-ci.org/apache/incubator-skywalking.svg?branch=master)](https://travis-ci.org/apache/incubator-skywalking) -[![Coverage Status](https://coveralls.io/repos/github/apache/incubator-skywalking/badge.svg?branch=master&u=1)](https://coveralls.io/github/apache/incubator-skywalking?branch=master) +[![Twitter URL](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/AsfSkyWalking) [![Join the chat at https://gitter.im/openskywalking/Lobby](https://badges.gitter.im/openskywalking/Lobby.svg)](https://gitter.im/openskywalking/Lobby) [![OpenTracing-1.x Badge](https://img.shields.io/badge/OpenTracing--1.x-enabled-blue.svg)](http://opentracing.io) diff --git a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/OffsetManager.java b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/OffsetManager.java index 12899710ef1b96a5f70c3f80d62c928b08139b66..fbd3d02514f5704beec7aa8e9b5a0e471539a088 100644 --- a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/OffsetManager.java +++ b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/OffsetManager.java @@ -28,6 +28,7 @@ import org.apache.skywalking.apm.collector.core.util.CollectionUtils; import org.apache.skywalking.apm.collector.core.util.Const; import org.apache.skywalking.apm.collector.core.util.FileUtils; import org.apache.skywalking.apm.collector.core.util.TimeBucketUtils; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,7 +71,10 @@ public enum OffsetManager { offset.deserialize(offsetRecord); initialized = true; - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::flush, 10, 3, TimeUnit.SECONDS); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate( + new RunnableWithExceptionProtection(this::flush, + t -> logger.error("flush offset file in background failure.", t) + ), 10, 3, TimeUnit.SECONDS); } } diff --git a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/SegmentBufferReader.java b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/SegmentBufferReader.java index d2e41f4e5cfa07ead630aac19b10671b304d0f7e..11005ea97cff8ab693f8e6f6686cb4be11ca9e5c 100644 --- a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/SegmentBufferReader.java +++ b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/buffer/SegmentBufferReader.java @@ -34,6 +34,7 @@ import org.apache.skywalking.apm.collector.core.util.CollectionUtils; import org.apache.skywalking.apm.collector.core.util.Const; import org.apache.skywalking.apm.collector.core.util.StringUtils; import org.apache.skywalking.apm.network.proto.UpstreamSegment; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +51,9 @@ public enum SegmentBufferReader { public void initialize(ModuleManager moduleManager) { this.moduleManager = moduleManager; - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::preRead, 3, 3, TimeUnit.SECONDS); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate( + new RunnableWithExceptionProtection(this::preRead, + t -> logger.error("Segment buffer pre read failure.", t)), 3, 3, TimeUnit.SECONDS); } public void setSegmentParserListenerManager(SegmentParserListenerManager listenerManager) { diff --git a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/SegmentStandardizationWorker.java b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/SegmentStandardizationWorker.java index 93d0c2ef08a92cbe5a9fd352516b9d6483edaa05..518a904309b4c9aad58e0817ff8ecb394dbb18d0 100644 --- a/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/SegmentStandardizationWorker.java +++ b/apm-collector/apm-collector-analysis/analysis-segment-parser/segment-parser-provider/src/main/java/org/apache/skywalking/apm/collector/analysis/segment/parser/provider/parser/standardization/SegmentStandardizationWorker.java @@ -26,6 +26,7 @@ import org.apache.skywalking.apm.collector.analysis.worker.model.base.AbstractLo import org.apache.skywalking.apm.collector.analysis.worker.model.base.AbstractLocalAsyncWorkerProvider; import org.apache.skywalking.apm.collector.analysis.worker.model.base.WorkerException; import org.apache.skywalking.apm.collector.core.module.ModuleManager; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +35,7 @@ import org.slf4j.LoggerFactory; */ public class SegmentStandardizationWorker extends AbstractLocalAsyncWorker { - private final Logger logger = LoggerFactory.getLogger(SegmentStandardizationWorker.class); + private static final Logger logger = LoggerFactory.getLogger(SegmentStandardizationWorker.class); public SegmentStandardizationWorker(ModuleManager moduleManager) { super(moduleManager); @@ -70,7 +71,9 @@ public class SegmentStandardizationWorker extends AbstractLocalAsyncWorker logger.error("Segment standardization failure.", t)), 10, 3, TimeUnit.SECONDS); } } } diff --git a/apm-collector/apm-collector-analysis/analysis-worker-model/src/main/java/org/apache/skywalking/apm/collector/analysis/worker/timer/PersistenceTimer.java b/apm-collector/apm-collector-analysis/analysis-worker-model/src/main/java/org/apache/skywalking/apm/collector/analysis/worker/timer/PersistenceTimer.java index dd3a2671906e3d775fc9edfccbf3e2d93af94e38..dd7a34252b943d67189ddf318192f93dff54160c 100644 --- a/apm-collector/apm-collector-analysis/analysis-worker-model/src/main/java/org/apache/skywalking/apm/collector/analysis/worker/timer/PersistenceTimer.java +++ b/apm-collector/apm-collector-analysis/analysis-worker-model/src/main/java/org/apache/skywalking/apm/collector/analysis/worker/timer/PersistenceTimer.java @@ -27,6 +27,7 @@ import org.apache.skywalking.apm.collector.analysis.worker.model.impl.Persistenc import org.apache.skywalking.apm.collector.core.module.ModuleManager; import org.apache.skywalking.apm.collector.storage.StorageModule; import org.apache.skywalking.apm.collector.storage.base.dao.IBatchDAO; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,7 +50,9 @@ public class PersistenceTimer { // final long timeInterval = EsConfig.Es.Persistence.Timer.VALUE * 1000; final long timeInterval = 3; IBatchDAO batchDAO = moduleManager.find(StorageModule.NAME).getService(IBatchDAO.class); - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(() -> extractDataAndSave(batchDAO, persistenceWorkers), 1, timeInterval, TimeUnit.SECONDS); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate( + new RunnableWithExceptionProtection(() -> extractDataAndSave(batchDAO, persistenceWorkers), + t -> logger.error("Extract data and save failure.", t)), 1, timeInterval, TimeUnit.SECONDS); } private void extractDataAndSave(IBatchDAO batchDAO, List persistenceWorkers) { diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java index 13f3548434875bb9e61d590885ba4137144c878f..ca152a492d161810fbb76b843ca9f4d7944b7cf9 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/DataTTLKeeperTimer.java @@ -35,11 +35,15 @@ import org.apache.skywalking.apm.collector.storage.dao.imp.IInstanceMinuteMetric import org.apache.skywalking.apm.collector.storage.dao.memorymp.IMemorySecondMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.mpoolmp.IMemoryPoolSecondMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMinuteMetricPersistenceDAO; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author peng-yongsheng */ public class DataTTLKeeperTimer { + private final Logger logger = LoggerFactory.getLogger(StorageModuleEsProvider.class); private final ModuleManager moduleManager; private final StorageModuleEsNamingListener namingListener; @@ -55,7 +59,9 @@ public class DataTTLKeeperTimer { } public void start() { - Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(this::delete, 1, 8, TimeUnit.HOURS); + Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate( + new RunnableWithExceptionProtection(this::delete, + t -> logger.error("Remove data in background failure.", t)), 1, 8, TimeUnit.HOURS); } private void delete() { diff --git a/apm-collector/pom.xml b/apm-collector/pom.xml index 2389168c7dbbbbdf1d2fb4f63ebe84667981edf7..70699a1dd571122b772734a998aa3558d0bd3433 100644 --- a/apm-collector/pom.xml +++ b/apm-collector/pom.xml @@ -49,6 +49,11 @@ + + org.apache.skywalking + apm-util + ${project.version} + org.slf4j slf4j-api diff --git a/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/RunnableWithExceptionProtection.java b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/RunnableWithExceptionProtection.java new file mode 100644 index 0000000000000000000000000000000000000000..d03e83258804076fd1d7116dff4bc7eb74fbc4a2 --- /dev/null +++ b/apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/RunnableWithExceptionProtection.java @@ -0,0 +1,45 @@ +/* + * 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.skywalking.apm.util; + +/** + * @author wusheng + */ +public class RunnableWithExceptionProtection implements Runnable { + private Runnable run; + private CallbackWhenException callback; + + public RunnableWithExceptionProtection(Runnable run, CallbackWhenException callback) { + this.run = run; + this.callback = callback; + } + + @Override + public void run() { + try { + run.run(); + } catch (Throwable t) { + callback.handle(t); + } + } + + public interface CallbackWhenException { + void handle(Throwable t); + } +} diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java index 15d185526eb42be7d663326df82fce67f220b611..8d47590e1d98dce63231d672d70aceffaec365b3 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/jvm/JVMService.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.agent.core.jvm; import io.grpc.ManagedChannel; @@ -43,6 +42,7 @@ import org.apache.skywalking.apm.agent.core.remote.GRPCChannelStatus; import org.apache.skywalking.apm.network.proto.JVMMetric; import org.apache.skywalking.apm.network.proto.JVMMetrics; import org.apache.skywalking.apm.network.proto.JVMMetricsServiceGrpc; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; /** * The JVMService represents a timer, @@ -57,6 +57,7 @@ public class JVMService implements BootService, Runnable { private volatile ScheduledFuture collectMetricFuture; private volatile ScheduledFuture sendMetricFuture; private Sender sender; + @Override public void beforeBoot() throws Throwable { queue = new LinkedBlockingQueue(Config.Jvm.BUFFER_SIZE); @@ -68,10 +69,19 @@ public class JVMService implements BootService, Runnable { public void boot() throws Throwable { collectMetricFuture = Executors .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("JVMService-produce")) - .scheduleAtFixedRate(this, 0, 1, TimeUnit.SECONDS); + .scheduleAtFixedRate(new RunnableWithExceptionProtection(this, new RunnableWithExceptionProtection.CallbackWhenException() { + @Override public void handle(Throwable t) { + logger.error("JVMService produces metrics failure.", t); + } + }), 0, 1, TimeUnit.SECONDS); sendMetricFuture = Executors .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("JVMService-consume")) - .scheduleAtFixedRate(sender, 0, 1, TimeUnit.SECONDS); + .scheduleAtFixedRate(new RunnableWithExceptionProtection(sender, new RunnableWithExceptionProtection.CallbackWhenException() { + @Override public void handle(Throwable t) { + logger.error("JVMService consumes and upload failure.", t); + } + } + ), 0, 1, TimeUnit.SECONDS); } @Override diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/MultiClassNameMatch.java similarity index 91% rename from apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java rename to apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/MultiClassNameMatch.java index 66b2e8840b2dc1841e73ebec307f6cdd7ca785d8..6453facdff99b37154118f3857aa3eba09dd7eb2 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/MultiClassNameMatch.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/match/MultiClassNameMatch.java @@ -17,14 +17,12 @@ */ -package org.apache.skywalking.apm.plugin.jdbc.mysql.define; +package org.apache.skywalking.apm.agent.core.plugin.match; import java.util.Arrays; import java.util.List; import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.matcher.ElementMatcher; -import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import org.apache.skywalking.apm.agent.core.plugin.match.IndirectMatch; import static net.bytebuddy.matcher.ElementMatchers.named; diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java index db5b3d992cc2796d1ad44934213640d917795225..6a223d61eae5985391493642cc186e4179a7b496 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/AppAndServiceRegisterClient.java @@ -46,6 +46,7 @@ import org.apache.skywalking.apm.network.proto.ApplicationRegisterServiceGrpc; import org.apache.skywalking.apm.network.proto.InstanceDiscoveryServiceGrpc; import org.apache.skywalking.apm.network.proto.NetworkAddressRegisterServiceGrpc; import org.apache.skywalking.apm.network.proto.ServiceNameDiscoveryServiceGrpc; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; /** * @author wusheng @@ -87,7 +88,11 @@ public class AppAndServiceRegisterClient implements BootService, GRPCChannelList public void boot() throws Throwable { applicationRegisterFuture = Executors .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("AppAndServiceRegisterClient")) - .scheduleAtFixedRate(this, 0, Config.Collector.APP_AND_SERVICE_REGISTER_CHECK_INTERVAL, TimeUnit.SECONDS); + .scheduleAtFixedRate(new RunnableWithExceptionProtection(this, new RunnableWithExceptionProtection.CallbackWhenException() { + @Override public void handle(Throwable t) { + logger.error("unexpected exception.", t); + } + }), 0, Config.Collector.APP_AND_SERVICE_REGISTER_CHECK_INTERVAL, TimeUnit.SECONDS); } @Override diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java index 8850ba9fd698f842b0a918ed037d5bdf98659966..f7910f71dcd0677df921bee67c092af00c80c12a 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/CollectorDiscoveryService.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.agent.core.remote; import java.util.concurrent.Executors; @@ -25,6 +24,9 @@ import java.util.concurrent.TimeUnit; import org.apache.skywalking.apm.agent.core.boot.BootService; import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory; import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.agent.core.logging.api.ILog; +import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; /** * The CollectorDiscoveryService is responsible for start {@link DiscoveryRestServiceClient}. @@ -32,6 +34,7 @@ import org.apache.skywalking.apm.agent.core.conf.Config; * @author wusheng */ public class CollectorDiscoveryService implements BootService { + private static final ILog logger = LogManager.getLogger(CollectorDiscoveryService.class); private ScheduledFuture future; @Override @@ -42,7 +45,12 @@ public class CollectorDiscoveryService implements BootService { @Override public void boot() throws Throwable { future = Executors.newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("CollectorDiscoveryService")) - .scheduleAtFixedRate(new DiscoveryRestServiceClient(), 0, + .scheduleAtFixedRate(new RunnableWithExceptionProtection(new DiscoveryRestServiceClient(), + new RunnableWithExceptionProtection.CallbackWhenException() { + @Override public void handle(Throwable t) { + logger.error("unexpected exception.", t); + } + }), 0, Config.Collector.DISCOVERY_CHECK_INTERVAL, TimeUnit.SECONDS); } diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java index 8cfca0b7b9b9461d62d92c3fc43a3d0bdb079fab..2f522f0fcc95de07ce1d93c421f66970863c1759 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/remote/GRPCChannelManager.java @@ -38,6 +38,7 @@ import org.apache.skywalking.apm.agent.core.conf.RemoteDownstreamConfig; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; import org.apache.skywalking.apm.agent.core.conf.Config; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; /** * @author wusheng @@ -60,7 +61,11 @@ public class GRPCChannelManager implements BootService, Runnable { public void boot() throws Throwable { connectCheckFuture = Executors .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("GRPCChannelManager")) - .scheduleAtFixedRate(this, 0, Config.Collector.GRPC_CHANNEL_CHECK_INTERVAL, TimeUnit.SECONDS); + .scheduleAtFixedRate(new RunnableWithExceptionProtection(this, new RunnableWithExceptionProtection.CallbackWhenException() { + @Override public void handle(Throwable t) { + logger.error("unexpected exception.", t); + } + }), 0, Config.Collector.GRPC_CHANNEL_CHECK_INTERVAL, TimeUnit.SECONDS); } @Override diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java index e2910bba6a3a722c314f4d6e11f19438aec001b3..c902e90fd2580f808b0f42be274850793b1c4d50 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/sampling/SamplingService.java @@ -30,6 +30,7 @@ import org.apache.skywalking.apm.agent.core.conf.Config; import org.apache.skywalking.apm.agent.core.context.trace.TraceSegment; import org.apache.skywalking.apm.agent.core.logging.api.ILog; import org.apache.skywalking.apm.agent.core.logging.api.LogManager; +import org.apache.skywalking.apm.util.RunnableWithExceptionProtection; /** * The SamplingService take charge of how to sample the {@link TraceSegment}. Every {@link TraceSegment}s @@ -66,12 +67,16 @@ public class SamplingService implements BootService { this.resetSamplingFactor(); ScheduledExecutorService service = Executors .newSingleThreadScheduledExecutor(new DefaultNamedThreadFactory("SamplingService")); - scheduledFuture = service.scheduleAtFixedRate(new Runnable() { + scheduledFuture = service.scheduleAtFixedRate(new RunnableWithExceptionProtection(new Runnable() { @Override public void run() { resetSamplingFactor(); } - }, 0, 3, TimeUnit.SECONDS); + }, new RunnableWithExceptionProtection.CallbackWhenException() { + @Override public void handle(Throwable t) { + logger.error("unexpected exception.", t); + } + }), 0, 3, TimeUnit.SECONDS); logger.debug("Agent sampling mechanism started. Sample {} traces in 10 seconds.", Config.Agent.SAMPLE_N_PER_3_SECS); } } diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java index e8605a35d4f81c43b2689070ad61d951dd051910..4afeb7f0cad6a2c1c3c2f93220f9ab8f682fc54b 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/CallableInstrumentation.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInst import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; /** * {@link CallableInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the {@link diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java index 27b38e1746f564e0071f6a2b504279d8d85ea2a3..f17d3da0416497922ae7fa59244123cee9bb0831 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/DriverInstrumentation.java @@ -22,7 +22,7 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.define; import org.apache.skywalking.apm.plugin.jdbc.define.AbstractDriverInstrumentation; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; /** * {@link DriverInstrumentation} presents that skywalking intercepts {@link com.mysql.jdbc.Driver}. diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java index 512b0c8ee4614c4d923fd41fef43a33f3d35705e..6c48601763a210ef0459798a134fa95da7dc128d 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/Mysql5xConnectionInstrumentation.java @@ -21,7 +21,7 @@ package org.apache.skywalking.apm.plugin.jdbc.mysql.define; import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; /** * {@link Mysql5xConnectionInstrumentation } interceptor {@link com.mysql.cj.jdbc.ConnectionImpl} and diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java index 6997cb7a58c6cd2cff7ded7f54de496d5a03cbeb..dc268942a481367fa42640201ca8041615d8bf2a 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/PreparedStatementInstrumentation.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; /** * {@link PreparedStatementInstrumentation} define that the mysql-2.x plugin intercepts the following methods in the diff --git a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java index 947e6b12c2f4d8e891433f3c451315b3b3c39f6b..a5078cad3b88a6f23c29a236ea2372c4f8752d9f 100644 --- a/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/mysql-5.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/mysql/define/StatementInstrumentation.java @@ -27,7 +27,7 @@ import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterc import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; -import static org.apache.skywalking.apm.plugin.jdbc.mysql.define.MultiClassNameMatch.byMultiClassMatch; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; /** * {@link StatementInstrumentation} intercepts the following methods in the {@link diff --git a/apm-sniffer/apm-sdk-plugin/pom.xml b/apm-sniffer/apm-sdk-plugin/pom.xml index 3a26042c5d92ae3a2f3c886384bc1f671972af20..0bba88f186d129e7814ba0b6c5dc50b235b49793 100644 --- a/apm-sniffer/apm-sdk-plugin/pom.xml +++ b/apm-sniffer/apm-sdk-plugin/pom.xml @@ -38,8 +38,6 @@ mongodb-3.x-plugin feign-default-http-9.x-plugin okhttp-3.x-plugin - resin-3.x-plugin - resin-4.x-plugin spring-plugins struts2-2.x-plugin nutz-plugins @@ -51,7 +49,6 @@ mysql-5.x-plugin h2-1.x-plugin postgresql-8.x-plugin - oracle-10.x-plugin rocketMQ-4.x-plugin elastic-job-2.x-plugin mongodb-2.x-plugin @@ -202,4 +199,43 @@ + + + + + include-ojdbc + + + ${basedir}/../../ci-dependencies/ojdbc14-10.2.0.4.0.jar + + + + oracle-10.x-plugin + + + + + include-resin-3 + + + ${basedir}/../../ci-dependencies/resin-3.0.9.jar + + + + resin-3.x-plugin + + + + + include-resin-4 + + + ${basedir}/../../ci-dependencies/resin-4.0.41.jar + + + + resin-4.x-plugin + + + diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java new file mode 100644 index 0000000000000000000000000000000000000000..6ad648c24253ce6b0d1d2a32fd08b6abc0732dff --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/PreparedStatementExecuteMethodsInterceptor.java @@ -0,0 +1,76 @@ +/* + * 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.skywalking.apm.plugin.jdbc.postgresql; + +import java.lang.reflect.Method; +import org.apache.skywalking.apm.agent.core.context.ContextManager; +import org.apache.skywalking.apm.agent.core.context.tag.Tags; +import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; +import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; +import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; + +/** + * {@link PreparedStatementExecuteMethodsInterceptor} create the exit span when the client call the interceptor methods. + * + * @author zhangxin + */ +public class PreparedStatementExecuteMethodsInterceptor implements InstanceMethodsAroundInterceptor { + @Override + public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + MethodInterceptResult result) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + ConnectionInfo connectInfo = cacheObject.getConnectionInfo(); + AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); + Tags.DB_TYPE.set(span, "sql"); + Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); + Tags.DB_STATEMENT.set(span, cacheObject.getSql()); + span.setComponent(connectInfo.getComponent()); + + SpanLayer.asDB(span); + } + + @Override + public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, + Object ret) throws Throwable { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.stopSpan(); + } + return ret; + } + + @Override public final void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, + Class[] argumentsTypes, Throwable t) { + StatementEnhanceInfos cacheObject = (StatementEnhanceInfos)objInst.getSkyWalkingDynamicField(); + if (cacheObject.getConnectionInfo() != null) { + ContextManager.activeSpan().errorOccurred().log(t); + } + } + + private String buildOperationName(ConnectionInfo connectionInfo, String methodName, String statementName) { + return connectionInfo.getDBType() + "/JDBI/" + statementName + "/" + methodName; + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java index ed198b3edf92a88d7139ccdb05a2d7c9b0961e6b..fd7562656c09ac264b1a17740f1923261c49085b 100644 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/StatementExecuteMethodsInterceptor.java @@ -16,7 +16,6 @@ * */ - package org.apache.skywalking.apm.plugin.jdbc.postgresql; import java.lang.reflect.Method; @@ -26,8 +25,8 @@ import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor; -import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult; +import org.apache.skywalking.apm.plugin.jdbc.define.StatementEnhanceInfos; import org.apache.skywalking.apm.plugin.jdbc.trace.ConnectionInfo; /** @@ -45,7 +44,7 @@ public class StatementExecuteMethodsInterceptor implements InstanceMethodsAround AbstractSpan span = ContextManager.createExitSpan(buildOperationName(connectInfo, method.getName(), cacheObject.getStatementName()), connectInfo.getDatabasePeer()); Tags.DB_TYPE.set(span, "sql"); Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName()); - Tags.DB_STATEMENT.set(span, cacheObject.getSql()); + Tags.DB_STATEMENT.set(span, (String)allArguments[0]); span.setComponent(connectInfo.getComponent()); SpanLayer.asDB(span); diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Variables.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Variables.java new file mode 100644 index 0000000000000000000000000000000000000000..d92d9658eb90cc4ac38c6b96e6a9a6c8a341c256 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/Variables.java @@ -0,0 +1,25 @@ +/* + * 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.skywalking.apm.plugin.jdbc.postgresql; + +public final class Variables { + public static final String PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.postgresql.PreparedStatementExecuteMethodsInterceptor"; + + public static final String PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR = "org.apache.skywalking.apm.plugin.jdbc.postgresql.StatementExecuteMethodsInterceptor"; +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java index 662428aa99e7a79d3c1aa3e4031dde9d1d544aec..1e4e6107b00629ed7183c0bba8f1cdb30b4226f4 100644 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/AbstractJdbc2StatementInstrumentation.java @@ -30,6 +30,8 @@ import org.apache.skywalking.apm.plugin.jdbc.postgresql.StatementExecuteMethodsI import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; +import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; /** * {@link AbstractJdbc2StatementInstrumentation} intercept the following methods that the class which extend {@link @@ -49,7 +51,7 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { private static final String ENHANCE_CLASS = "org.postgresql.jdbc2.AbstractJdbc2Statement"; - private static final String INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.StatementExecuteMethodsInterceptor"; + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[0]; @@ -60,16 +62,27 @@ public class AbstractJdbc2StatementInstrumentation extends ClassInstanceMethodsE new InstanceMethodsInterceptPoint() { @Override public ElementMatcher getMethodsMatcher() { return named("execute").and(takesArguments(0)) - .or(named("execute").and(takesArguments(1))) - .or(named("executeBatch")) .or(named("executeQuery").and(takesArguments(0))) + .or(named("executeUpdate").and(takesArguments(0))); + } + + @Override public String getMethodsInterceptor() { + return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + }, + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute").and(takesArguments(1)) .or(named("executeQuery").and(takesArguments(1))) - .or(named("executeUpdate").and(takesArguments(0))) .or(named("executeUpdate").and(takesArguments(1))); } @Override public String getMethodsInterceptor() { - return INTERCEPTOR_CLASS; + return PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; } @Override public boolean isOverrideArgs() { diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java index 24cc182e0751371d278401762c7ddf8864255ffe..64250bc0e9210a8e17c3380f05559061bca072af 100644 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/ConnectionInstrumentation.java @@ -29,7 +29,7 @@ import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; -import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.agent.core.plugin.match.MultiClassNameMatch.byMultiClassMatch; /** * {@link ConnectionInstrumentation} intercept the following methods that the class which extend {@link @@ -49,8 +49,11 @@ import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { private static final String PREPARE_STATEMENT_METHOD_WITH_STRING_ARRAY_INTERCEPTOR_CLASS = "org.apache.skywalking.apm.plugin.jdbc.postgresql.JDBCPrepareStatementWithStringArrayInterceptor"; - public static final String ENHANCE_CLASS = "org.postgresql.jdbc.PgConnection"; + public static final String PG_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc.PgConnection"; public static final String STRING_ARRAY_ARGUMENT_TYPE = "java.lang.String[]"; + public static final String PG_JDBC42_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc42.Jdbc42Connection"; + public static final String PG_JDBC3_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc3g.Jdbc3gConnection"; + public static final String PG_JDBC4_CONNECTION_ENHANCE_CLASS = "org.postgresql.jdbc4.Jdbc4Connection"; @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { return new ConstructorInterceptPoint[0]; @@ -127,6 +130,6 @@ public class ConnectionInstrumentation extends ClassInstanceMethodsEnhancePlugin } @Override protected ClassMatch enhanceClass() { - return byName(ENHANCE_CLASS); + return byMultiClassMatch(PG_CONNECTION_ENHANCE_CLASS, PG_JDBC42_CONNECTION_ENHANCE_CLASS, PG_JDBC3_CONNECTION_ENHANCE_CLASS, PG_JDBC4_CONNECTION_ENHANCE_CLASS); } } diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgCallableStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgCallableStatementInstrumentation.java new file mode 100644 index 0000000000000000000000000000000000000000..32ecb250059e5575de48a2e3127831cbce1e1a01 --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgCallableStatementInstrumentation.java @@ -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.skywalking.apm.plugin.jdbc.postgresql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; + +public class PgCallableStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("executeWithFlags").and(takesArgumentWithType(0, "int")) + .or(named("executeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName("org.postgresql.jdbc.PgCallableStatement"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgPreparedStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgPreparedStatementInstrumentation.java new file mode 100644 index 0000000000000000000000000000000000000000..5ca582fe37b3dffbe699cdf8669b68703796c34c --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgPreparedStatementInstrumentation.java @@ -0,0 +1,65 @@ +/* + * 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.skywalking.apm.plugin.jdbc.postgresql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; + +/** + * @author zhang xin + */ +public class PgPreparedStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute").and(takesArgumentWithType(0, "java.lang.String")) + .or(named("executeWithFlags").and(takesArgumentWithType(0, "int"))) + .or(named("executeQuery")) + .or(named("executeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return PG_PREPARED_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName("org.postgresql.jdbc.PgPreparedStatement"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgStatementInstrumentation.java b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgStatementInstrumentation.java new file mode 100644 index 0000000000000000000000000000000000000000..8fe16747cc250e18d18001e540f76487cddbc29b --- /dev/null +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/jdbc/postgresql/define/PgStatementInstrumentation.java @@ -0,0 +1,68 @@ +/* + * 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.skywalking.apm.plugin.jdbc.postgresql.define; + +import net.bytebuddy.description.method.MethodDescription; +import net.bytebuddy.matcher.ElementMatcher; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint; +import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine; +import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch; + +import static net.bytebuddy.matcher.ElementMatchers.named; +import static org.apache.skywalking.apm.agent.core.plugin.bytebuddy.ArgumentTypeNameMatch.takesArgumentWithType; +import static org.apache.skywalking.apm.agent.core.plugin.match.NameMatch.byName; +import static org.apache.skywalking.apm.plugin.jdbc.postgresql.Variables.PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; + +/** + * @author zhang xin + */ +public class PgStatementInstrumentation extends ClassInstanceMethodsEnhancePluginDefine { + + @Override protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() { + return new ConstructorInterceptPoint[0]; + } + + @Override protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() { + return new InstanceMethodsInterceptPoint[] { + new InstanceMethodsInterceptPoint() { + @Override public ElementMatcher getMethodsMatcher() { + return named("execute").and(takesArgumentWithType(0, "java.lang.String")) + .or(named("execute").and(takesArgumentWithType(0, "java.lang.String[]"))) + .or(named("executeQuery")) + .or(named("executeUpdate").and(takesArgumentWithType(0, "java.lang.String[]"))) + .or(named("executeUpdate").and(takesArgumentWithType(0, "java.lang.String"))) + .or(named("executeLargeUpdate")); + } + + @Override public String getMethodsInterceptor() { + return PG_STATEMENT_EXECUTE_METHOD_INTERCEPTOR; + } + + @Override public boolean isOverrideArgs() { + return false; + } + } + }; + } + + @Override protected ClassMatch enhanceClass() { + return byName("org.postgresql.jdbc.PgStatement"); + } +} diff --git a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/resources/skywalking-plugin.def b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/resources/skywalking-plugin.def index 77839a7d8c94b638375d323eb9872fe64b1e4570..549f50d302bf6869b87d886a14b2846f3cf3f00e 100644 --- a/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/resources/skywalking-plugin.def +++ b/apm-sniffer/apm-sdk-plugin/postgresql-8.x-plugin/src/main/resources/skywalking-plugin.def @@ -3,3 +3,6 @@ postgresql-8.x=org.apache.skywalking.apm.plugin.jdbc.postgresql.define.Jdbc3Conn postgresql-8.x=org.apache.skywalking.apm.plugin.jdbc.postgresql.define.Jdbc4ConnectionInstrumentation postgresql-8.x=org.apache.skywalking.apm.plugin.jdbc.postgresql.define.ConnectionInstrumentation postgresql-8.x=org.apache.skywalking.apm.plugin.jdbc.postgresql.define.AbstractJdbc2StatementInstrumentation +postgresql-8.x=org.apache.skywalking.apm.plugin.jdbc.postgresql.define.PgCallableStatementInstrumentation +postgresql-8.x=org.apache.skywalking.apm.plugin.jdbc.postgresql.define.PgPreparedStatementInstrumentation +postgresql-8.x=org.apache.skywalking.apm.plugin.jdbc.postgresql.define.PgStatementInstrumentation diff --git a/ci-dependencies/ojdbc14-10.2.0.4.0.jar b/ci-dependencies/ojdbc14-10.2.0.4.0.jar deleted file mode 100644 index f41cf1ae9fb28a9defda0b9e78e7faa3ef36d555..0000000000000000000000000000000000000000 Binary files a/ci-dependencies/ojdbc14-10.2.0.4.0.jar and /dev/null differ diff --git a/ci-dependencies/resin-4.0.41.jar b/ci-dependencies/resin-4.0.41.jar deleted file mode 100644 index 9e04f4ce77abc269589b35e84a04624733adf0dd..0000000000000000000000000000000000000000 Binary files a/ci-dependencies/resin-4.0.41.jar and /dev/null differ diff --git a/docs/Supported-list.md b/docs/Supported-list.md index 54b5744dc9ef85d5d9370512e8e5c1a230c71ceb..c4f84c5a4406c6e5960b2573311d2ef8becc62d5 100644 --- a/docs/Supported-list.md +++ b/docs/Supported-list.md @@ -5,8 +5,8 @@ * Spring MVC 3.x, 4.x with servlet 3.x * [Nutz Web Framework](https://github.com/nutzam/nutz) 1.x * [Struts2 MVC](http://struts.apache.org/) 2.3.x -> 2.5.x - * [Resin](http://www.caucho.com/resin-4.0/) 3 - * [Resin](http://www.caucho.com/resin-4.0/) 4 + * [Resin](http://www.caucho.com/resin-4.0/) 3 (Optional¹) + * [Resin](http://www.caucho.com/resin-4.0/) 4 (Optional¹) * [Jetty Server](http://www.eclipse.org/jetty/) 9 * HTTP Client * [Feign](https://github.com/OpenFeign/feign) 9.x @@ -17,7 +17,7 @@ * [Jetty Client](http://www.eclipse.org/jetty/) 9 * JDBC * Mysql Driver 5.x, 6.x - * Oracle Driver + * Oracle Driver (Optional¹) * H2 Driver * [Sharding-JDBC](https://github.com/shardingjdbc/sharding-jdbc) 1.5.x * PostgreSQL Driver 8.x, 9.x, 42.x @@ -44,3 +44,5 @@ * OpenTracing community supported * Motan * Hprose-java + +¹Required dependencies for these components must be first manually downloaded before being built, due to license incompatibilities. For this reason these components are not by default included in the SkyWalking releases. \ No newline at end of file diff --git a/docs/en/How-to-build.md b/docs/en/How-to-build.md index b21e504f85df0fb627f6fcca2d53f8803f629d7f..c6ea808e805c48f7a9daf1bc0a0155ca07dab15b 100644 --- a/docs/en/How-to-build.md +++ b/docs/en/How-to-build.md @@ -11,4 +11,12 @@ This document helps people to compile and build the project in your maven and ID 1. Run `mvn compile -Dmaven.test.skip=true` to compile project and generate source codes. Because we use gRPC and protobuf. 1. Set **Generated Source Codes** folders. * `grpc-java` and `java` folders in **apm-protocol/apm-network/target/generated-sources/protobuf** - * `grpc-java` and `java` folders in **apm-collector/apm-collector-remote/apm-remote-grpc-provider/target/protobuf** \ No newline at end of file + * `grpc-java` and `java` folders in **apm-collector/apm-collector-remote/apm-remote-grpc-provider/target/protobuf** + +## Building Resin-3, Resin-4, and OJDBC sdk plugins +Due to license incompatibilities/restrictions these plugins under `apm-sniffer/apm-sdk-plugin/` are not built by default. +Download them manually into the `ci-dependencies/` directory and the plugins will be included in the maven reactor and built. +The names of the artifacts downloaded and placed in the `ci-dependencies/` directory must be exact: +* resin-3.0.9.jar +* resin-4.0.41.jar +* ojdbc14-10.2.0.4.0.jar diff --git a/pom.xml b/pom.xml index 371a47c6b82452a4340c8b133f47a983288ecad1..3b60d2e26ed44e42b56338d050d46093e03b29c0 100644 --- a/pom.xml +++ b/pom.xml @@ -130,46 +130,6 @@ ${project.basedir}/ci-dependencies - - install-ojdbc - false - process-resources - - exec - - - mvn - - install:install-file - -Dfile=ojdbc14-10.2.0.4.0.jar - -DgroupId=com.oracle - -DartifactId=ojdbc14 - -Dversion=10.2.0.4.0 - -Dpackaging=jar - - ${project.basedir}/ci-dependencies - - - - install-resin - false - process-resources - - exec - - - mvn - - install:install-file - -Dfile=resin-4.0.41.jar - -DgroupId=com.caucho - -DartifactId=resin - -Dversion=4.0.41 - -Dpackaging=jar - - ${project.basedir}/ci-dependencies - - install-jmxri false @@ -318,4 +278,129 @@ + + + + + + install-ojdbc + + + ${basedir}/ci-dependencies/ojdbc14-10.2.0.4.0.jar + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + install-ojdbc + false + process-resources + + exec + + + mvn + + install:install-file + -Dfile=ojdbc14-10.2.0.4.0.jar + -DgroupId=com.oracle + -DartifactId=ojdbc14 + -Dversion=10.2.0.4.0 + -Dpackaging=jar + + ${project.basedir}/ci-dependencies + + + + + + + + + + install-resin-3 + + + ${basedir}/ci-dependencies/resin-3.0.9.jar + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + install-resin-3 + false + process-resources + + exec + + + mvn + + install:install-file + -Dfile=resin-3.0.9.jar + -DgroupId=com.caucho + -DartifactId=resin + -Dversion=3.0.9 + -Dpackaging=jar + + ${project.basedir}/ci-dependencies + + + + + + + + + + install-resin-4 + + + ${basedir}/ci-dependencies/resin-4.0.41.jar + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + install-resin-4 + false + process-resources + + exec + + + mvn + + install:install-file + -Dfile=resin-4.0.41.jar + -DgroupId=com.caucho + -DartifactId=resin + -Dversion=4.0.41 + -Dpackaging=jar + + ${project.basedir}/ci-dependencies + + + + + + + + +