Skip to content

Commit

Permalink
[#4661] Isolate domain model and transport model
Browse files Browse the repository at this point in the history
 - Refactor stat module
  • Loading branch information
emeroad committed Oct 11, 2018
1 parent bb9e9d4 commit 047c455
Show file tree
Hide file tree
Showing 66 changed files with 642 additions and 911 deletions.
Expand Up @@ -26,7 +26,7 @@ public class DefaultBufferMetricTest {

@Test
public void getSnapshot() {
DefaultBufferMetric defaultBufferMetric = new DefaultBufferMetric();
BufferMetric defaultBufferMetric = new DefaultBufferMetric();
BufferMetricSnapshot snapshot = defaultBufferMetric.getSnapshot();

Assert.assertNotEquals(snapshot.getDirectCount(), BufferMetric.UNCOLLECTED_VALUE);
Expand Down
18 changes: 12 additions & 6 deletions profiler-test/src/main/java/com/navercorp/pinpoint/test/Item.java
Expand Up @@ -16,7 +16,7 @@

package com.navercorp.pinpoint.test;

import org.apache.thrift.TBase;
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;

/**
* @author Woonduk Kang(emeroad)
Expand All @@ -29,15 +29,17 @@ public class Item implements Comparable<Item> {
private final int sequence;
private final int asyncId;
private final int asyncSequence;
private final TraceRoot traceRoot;

public Item(Object value, long time, long spanId, int sequence) {
this(value, time, spanId, sequence, OrderedSpanRecorder.ASYNC_ID_NOT_SET, OrderedSpanRecorder.ASYNC_SEQUENCE_NOT_SET);
public Item(Object value, long time, TraceRoot traceRoot, int sequence) {
this(value, time, traceRoot, sequence, OrderedSpanRecorder.ASYNC_ID_NOT_SET, OrderedSpanRecorder.ASYNC_SEQUENCE_NOT_SET);
}

public Item(Object value, long time, long spanId, int sequence, int asyncId, int asyncSequence) {
public Item(Object value, long time, TraceRoot traceRoot, int sequence, int asyncId, int asyncSequence) {
this.value = value;
this.time = time;
this.spanId = spanId;
this.traceRoot = traceRoot;
this.spanId = traceRoot.getTraceId().getSpanId();
this.sequence = sequence;
this.asyncId = asyncId;
this.asyncSequence = asyncSequence;
Expand All @@ -51,6 +53,10 @@ public long getSpanId() {
return spanId;
}

public TraceRoot getTraceRoot() {
return traceRoot;
}

@Override
public int compareTo(Item o) {
if (this.asyncId == OrderedSpanRecorder.ASYNC_ID_NOT_SET && o.asyncId == OrderedSpanRecorder.ASYNC_ID_NOT_SET) {
Expand Down Expand Up @@ -126,7 +132,7 @@ public String toString() {
", sequence=" + sequence +
", asyncId=" + asyncId +
", asyncSequence=" + asyncSequence +
", traceRoot=" + traceRoot +
'}';
}

}
Expand Up @@ -26,6 +26,7 @@
import com.navercorp.pinpoint.profiler.context.Span;
import com.navercorp.pinpoint.profiler.context.SpanChunk;
import com.navercorp.pinpoint.profiler.context.SpanEvent;
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;


/**
Expand Down Expand Up @@ -57,31 +58,12 @@ public synchronized boolean handleSend(Object data) {
return false;
}

public synchronized Span findTSpan(long spanId) {
Span tSpan = null;
for (Item item : list) {
final Object value = item.getValue();
if (value instanceof Span) {
if (tSpan != null) {
throw new IllegalStateException("duplicate span found " + list);
}
final Span span = (Span) value;
if (span.getTraceRoot().getTraceId().getSpanId() == spanId) {
tSpan = span;
}
}
}
if (tSpan == null) {
throw new IllegalStateException("tSpan not found " + list);
}
return tSpan;
}

private void insertSpan(Span span) {
long startTime = span.getStartTime();
long spanId = span.getTraceRoot().getTraceId().getSpanId();
TraceRoot traceRoot = span.getTraceRoot();

Item item = new Item(span, startTime, spanId, ROOT_SEQUENCE);
Item item = new Item(span, startTime, traceRoot, ROOT_SEQUENCE);
insertItem(item);
}

Expand All @@ -108,8 +90,7 @@ private void handleSpanEvent(SpanChunk spanChunk) {
}

long startTime = event.getStartTime();
long spanId = spanChunk.getTraceRoot().getTraceId().getSpanId();
Item item = new Item(event, startTime, spanId, event.getSequence(), asyncId, asyncSequence);
Item item = new Item(event, startTime, spanChunk.getTraceRoot(), event.getSequence(), asyncId, asyncSequence);
insertItem(item);
}
}
Expand Down
Expand Up @@ -48,6 +48,7 @@
import com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService;
import com.navercorp.pinpoint.profiler.context.Span;
import com.navercorp.pinpoint.profiler.context.SpanEvent;
import com.navercorp.pinpoint.profiler.context.id.TraceRoot;
import com.navercorp.pinpoint.profiler.context.module.DefaultApplicationContext;
import com.navercorp.pinpoint.profiler.context.module.SpanDataSender;
import com.navercorp.pinpoint.profiler.sender.DataSender;
Expand Down Expand Up @@ -878,8 +879,8 @@ public void verifyIsLoggingTransactionInfo(LoggingInfo loggingInfo) {
+ " but loggingTransactionInfo value invalid.");
}

final Span span = findSpan(item);
final byte loggingTransactionInfo = span.getTraceRoot().getShared().getLoggingInfo();
final TraceRoot traceRoot = item.getTraceRoot();
final byte loggingTransactionInfo = traceRoot.getShared().getLoggingInfo();
if (loggingTransactionInfo != loggingInfo.getCode()) {
LoggingInfo code = LoggingInfo.searchByCode(loggingTransactionInfo);
if (code != null) {
Expand All @@ -893,24 +894,5 @@ public void verifyIsLoggingTransactionInfo(LoggingInfo loggingInfo) {
}
}

private Span findSpan(Item item) {
final Object tBase = item.getValue();
if (tBase instanceof Span) {
final Span span = (Span) tBase;
return span;
} else if (tBase instanceof SpanEvent) {
OrderedSpanRecorder recorder = getRecorder();
return recorder.findTSpan(item.getSpanId());
} else {
throw new IllegalArgumentException("Unexpected type: " + getActual(item));
}
}

private String getActual(Object actual) {
if (actual == null) {
return "actual is null";
}
return actual.getClass().getName();
}

}
@@ -1,5 +1,5 @@
/*
* Copyright 2017 NAVER Corp.
* Copyright 2018 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,8 @@ public Module newModule(AgentOption agentOption) {
final Module applicationContextModule = new ApplicationContextModule();
final Module rpcModule = new RpcModule();
final Module statsModule = new StatsModule();
final Module thriftStatsModule = new ThriftStatsModule();

return Modules.combine(config, pluginModule, applicationContextModule, rpcModule, statsModule);
return Modules.combine(config, pluginModule, applicationContextModule, rpcModule, statsModule, thriftStatsModule);
}
}
Expand Up @@ -18,40 +18,18 @@

import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.navercorp.pinpoint.profiler.context.provider.stat.activethread.ActiveTraceMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.activethread.ActiveTraceMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.cpu.CpuLoadMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.cpu.CpuLoadMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.datasource.DataSourceMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.datasource.DataSourceMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.deadlock.DeadlockMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.deadlock.DeadlockMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.buffer.BufferMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.buffer.BufferMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.filedescriptor.FileDescriptorMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.filedescriptor.FileDescriptorMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.jvmgc.DetailedGarbageCollectorMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.jvmgc.DetailedMemoryMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.jvmgc.GarbageCollectorMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.jvmgc.JvmGcMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.jvmgc.MemoryMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.response.ResponseTimeMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.response.ResponseTimeMetricProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.transaction.TransactionMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.transaction.TransactionMetricProvider;
import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.activethread.ActiveTraceMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.cpu.CpuLoadMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.datasource.DataSourceMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.deadlock.DeadlockMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.buffer.BufferMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.filedescriptor.FileDescriptorMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.jvmgc.JvmGcMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.response.ResponseTimeMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.transaction.TransactionMetricCollector;
import com.navercorp.pinpoint.profiler.monitor.metric.activethread.ActiveTraceMetric;
import com.navercorp.pinpoint.profiler.monitor.metric.cpu.CpuLoadMetric;
import com.navercorp.pinpoint.profiler.monitor.metric.datasource.DataSourceMetric;
Expand All @@ -64,7 +42,6 @@
import com.navercorp.pinpoint.profiler.monitor.metric.memory.MemoryMetric;
import com.navercorp.pinpoint.profiler.monitor.metric.response.ResponseTimeMetric;
import com.navercorp.pinpoint.profiler.monitor.metric.transaction.TransactionMetric;
import com.navercorp.pinpoint.thrift.dto.TAgentStat;

/**
* @author Woonduk Kang(emeroad)
Expand All @@ -77,39 +54,35 @@ protected void configure() {
binder().requireAtInjectOnConstructors();
binder().disableCircularProxies();


// gc
bind(MemoryMetric.class).toProvider(MemoryMetricProvider.class).in(Scopes.SINGLETON);
bind(DetailedMemoryMetric.class).toProvider(DetailedMemoryMetricProvider.class).in(Scopes.SINGLETON);
bind(GarbageCollectorMetric.class).toProvider(GarbageCollectorMetricProvider.class).in(Scopes.SINGLETON);
bind(DetailedGarbageCollectorMetric.class).toProvider(DetailedGarbageCollectorMetricProvider.class).in(Scopes.SINGLETON);
bind(JvmGcMetricCollector.class).toProvider(JvmGcMetricCollectorProvider.class).in(Scopes.SINGLETON);

// cpu
bind(CpuLoadMetric.class).toProvider(CpuLoadMetricProvider.class).in(Scopes.SINGLETON);
bind(CpuLoadMetricCollector.class).toProvider(CpuLoadMetricCollectorProvider.class).in(Scopes.SINGLETON);

// FD
bind(FileDescriptorMetric.class).toProvider(FileDescriptorMetricProvider.class).in(Scopes.SINGLETON);
bind(FileDescriptorMetricCollector.class).toProvider(FileDescriptorMetricCollectorProvider.class).in(Scopes.SINGLETON);

// buffer
bind(BufferMetric.class).toProvider(BufferMetricProvider.class).in(Scopes.SINGLETON);
bind(BufferMetricCollector.class).toProvider(BufferMetricCollectorProvider.class).in(Scopes.SINGLETON);

// transaction
bind(TransactionMetric.class).toProvider(TransactionMetricProvider.class).in(Scopes.SINGLETON);
bind(TransactionMetricCollector.class).toProvider(TransactionMetricCollectorProvider.class).in(Scopes.SINGLETON);

// activeTrace
bind(ActiveTraceMetric.class).toProvider(ActiveTraceMetricProvider.class).in(Scopes.SINGLETON);
bind(ActiveTraceMetricCollector.class).toProvider(ActiveTraceMetricCollectorProvider.class).in(Scopes.SINGLETON);

// responseTime
bind(ResponseTimeMetric.class).toProvider(ResponseTimeMetricProvider.class).in(Scopes.SINGLETON);
bind(ResponseTimeMetricCollector.class).toProvider(ResponseTimeMetricCollectorProvider.class).in(Scopes.SINGLETON);

// datasource
bind(DataSourceMetric.class).toProvider(DataSourceMetricProvider.class).in(Scopes.SINGLETON);
bind(DataSourceMetricCollector.class).toProvider(DataSourceMetricCollectorProvider.class).in(Scopes.SINGLETON);

// deadlock
bind(DeadlockMetric.class).toProvider(DeadlockMetricProvider.class).in(Scopes.SINGLETON);
bind(DeadlockMetricCollector.class).toProvider(DeadlockMetricCollectorProvider.class).in(Scopes.SINGLETON);

bind(new TypeLiteral<AgentStatMetricCollector<TAgentStat>>() {})
.annotatedWith(Names.named("AgentStatCollector"))
.to(AgentStatCollector.class).in(Scopes.SINGLETON);
}
}
@@ -0,0 +1,98 @@
/*
* Copyright 2018 NAVER Corp.
*
* 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.navercorp.pinpoint.profiler.context.module;

import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.navercorp.pinpoint.profiler.context.provider.stat.activethread.ActiveTraceMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.buffer.BufferMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.cpu.CpuLoadMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.datasource.DataSourceMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.deadlock.DeadlockMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.filedescriptor.FileDescriptorMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.jvmgc.JvmGcMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.response.ResponseTimeMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.context.provider.stat.transaction.TransactionMetricCollectorProvider;
import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatCollector;
import com.navercorp.pinpoint.profiler.monitor.collector.AgentStatMetricCollector;
import com.navercorp.pinpoint.thrift.dto.TActiveTrace;
import com.navercorp.pinpoint.thrift.dto.TAgentStat;
import com.navercorp.pinpoint.thrift.dto.TCpuLoad;
import com.navercorp.pinpoint.thrift.dto.TDataSourceList;
import com.navercorp.pinpoint.thrift.dto.TDeadlock;
import com.navercorp.pinpoint.thrift.dto.TDirectBuffer;
import com.navercorp.pinpoint.thrift.dto.TFileDescriptor;
import com.navercorp.pinpoint.thrift.dto.TJvmGc;
import com.navercorp.pinpoint.thrift.dto.TResponseTime;
import com.navercorp.pinpoint.thrift.dto.TTransaction;

/**
* @author Woonduk Kang(emeroad)
*/
public class ThriftStatsModule extends AbstractModule {

@Override
protected void configure() {
binder().requireExplicitBindings();
binder().requireAtInjectOnConstructors();
binder().disableCircularProxies();

// gc
TypeLiteral<AgentStatMetricCollector<TJvmGc>> jvmGcCollector = new TypeLiteral<AgentStatMetricCollector<TJvmGc>>() {};
bind(jvmGcCollector).toProvider(JvmGcMetricCollectorProvider.class).in(Scopes.SINGLETON);

// cpu
TypeLiteral<AgentStatMetricCollector<TCpuLoad>> cpuLoadCollector = new TypeLiteral<AgentStatMetricCollector<TCpuLoad>>() {};
bind(cpuLoadCollector).toProvider(CpuLoadMetricCollectorProvider.class).in(Scopes.SINGLETON);

// FD
TypeLiteral<AgentStatMetricCollector<TFileDescriptor>> fdCollector = new TypeLiteral<AgentStatMetricCollector<TFileDescriptor>>() {};
bind(fdCollector).toProvider(FileDescriptorMetricCollectorProvider.class).in(Scopes.SINGLETON);

// buffer
TypeLiteral<AgentStatMetricCollector<TDirectBuffer>> bufferCollector = new TypeLiteral<AgentStatMetricCollector<TDirectBuffer>>() {};
bind(bufferCollector).toProvider(BufferMetricCollectorProvider.class).in(Scopes.SINGLETON);

// transaction
TypeLiteral<AgentStatMetricCollector<TTransaction>> transactionCollector = new TypeLiteral<AgentStatMetricCollector<TTransaction>>() {};
bind(transactionCollector).toProvider(TransactionMetricCollectorProvider.class).in(Scopes.SINGLETON);

// activeTrace
TypeLiteral<AgentStatMetricCollector<TActiveTrace>> activeTraceCollector = new TypeLiteral<AgentStatMetricCollector<TActiveTrace>>() {};
bind(activeTraceCollector).toProvider(ActiveTraceMetricCollectorProvider.class).in(Scopes.SINGLETON);

// responseTime
TypeLiteral<AgentStatMetricCollector<TResponseTime>> responseTimeCollector = new TypeLiteral<AgentStatMetricCollector<TResponseTime>>() {};
bind(responseTimeCollector).toProvider(ResponseTimeMetricCollectorProvider.class).in(Scopes.SINGLETON);

// datasource
TypeLiteral<AgentStatMetricCollector<TDataSourceList>> datasourceCollector = new TypeLiteral<AgentStatMetricCollector<TDataSourceList>>() {};
bind(datasourceCollector).toProvider(DataSourceMetricCollectorProvider.class).in(Scopes.SINGLETON);

// deadlock
TypeLiteral<AgentStatMetricCollector<TDeadlock>> deadlockCollector = new TypeLiteral<AgentStatMetricCollector<TDeadlock>>() {};
bind(deadlockCollector).toProvider(DeadlockMetricCollectorProvider.class).in(Scopes.SINGLETON);

// stat
TypeLiteral<AgentStatMetricCollector<TAgentStat>> statMetric = new TypeLiteral<AgentStatMetricCollector<TAgentStat>>() {};
bind(statMetric).annotatedWith(Names.named("AgentStatCollector"))
.to(AgentStatCollector.class).in(Scopes.SINGLETON);
}

}
@@ -1,5 +1,5 @@
/*
* Copyright 2017 NAVER Corp.
* Copyright 2018 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,8 @@
import com.navercorp.pinpoint.common.util.SystemPropertyKey;
import com.navercorp.pinpoint.profiler.JvmInformation;
import com.navercorp.pinpoint.profiler.monitor.metric.gc.GarbageCollectorMetric;
import com.navercorp.pinpoint.profiler.monitor.metric.gc.JvmGcType;
import com.navercorp.pinpoint.profiler.monitor.metric.gc.UnknownGarbageCollectorMetric;
import com.navercorp.pinpoint.thrift.dto.TJvmGcType;

/**
* @author HyunGil Jeong
Expand All @@ -45,7 +45,7 @@ public JvmInformationProvider() {
}

public JvmInformation get() {
TJvmGcType gcType = garbageCollectorMetric.getGcType();
JvmGcType gcType = garbageCollectorMetric.getGcType();
return new JvmInformation(jvmVersion, gcType.getValue());
}
}

0 comments on commit 047c455

Please sign in to comment.