-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
274 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...c/main/java/com/navercorp/pinpoint/profiler/context/grpc/GrpcUriStatMessageConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2020 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.grpc; | ||
|
||
import com.navercorp.pinpoint.grpc.trace.PAgentUriStat; | ||
import com.navercorp.pinpoint.grpc.trace.PEachUriStat; | ||
import com.navercorp.pinpoint.grpc.trace.PUriHistogram; | ||
import com.navercorp.pinpoint.profiler.context.thrift.MessageConverter; | ||
import com.navercorp.pinpoint.profiler.monitor.metric.uri.AgentUriStatData; | ||
import com.navercorp.pinpoint.profiler.monitor.metric.uri.EachUriStatData; | ||
import com.navercorp.pinpoint.profiler.monitor.metric.uri.UriStatHistogram; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author Taejin Koo | ||
*/ | ||
public class GrpcUriStatMessageConverter implements MessageConverter<PAgentUriStat> { | ||
|
||
private final static PUriHistogram EMPTY_DETAILED_DATA_INSTANCE = PUriHistogram.getDefaultInstance(); | ||
|
||
@Override | ||
public PAgentUriStat toMessage(Object message) { | ||
if (!(message instanceof AgentUriStatData)) { | ||
return null; | ||
} | ||
|
||
return createPAgentUriStat((AgentUriStatData) message); | ||
} | ||
|
||
private PAgentUriStat createPAgentUriStat(AgentUriStatData agentUriStatData) { | ||
long baseTimestamp = agentUriStatData.getBaseTimestamp(); | ||
int interval = agentUriStatData.getInterval(); | ||
|
||
PAgentUriStat.Builder builder = PAgentUriStat.newBuilder(); | ||
builder.setTimestamp(baseTimestamp); | ||
builder.setInterval(interval); | ||
|
||
Collection<EachUriStatData> allUriStatData = agentUriStatData.getAllUriStatData(); | ||
for (EachUriStatData eachUriStatData : allUriStatData) { | ||
PEachUriStat pEachUriStat = createPEachUriStat(eachUriStatData); | ||
builder.addEachUriStat(pEachUriStat); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
private PEachUriStat createPEachUriStat(EachUriStatData eachUriStatData) { | ||
String uri = eachUriStatData.getUri(); | ||
|
||
PEachUriStat.Builder builder = PEachUriStat.newBuilder(); | ||
builder.setUri(uri); | ||
|
||
UriStatHistogram totalHistogram = eachUriStatData.getTotalHistogram(); | ||
PUriHistogram totalPUriHistogram = createPUriHistogram(totalHistogram); | ||
builder.setTotalHistogram(totalPUriHistogram); | ||
|
||
UriStatHistogram failedHistogram = eachUriStatData.getFailedHistogram(); | ||
PUriHistogram failedPUriHistogram = createPUriHistogram(failedHistogram); | ||
builder.setFailedHistogram(failedPUriHistogram); | ||
|
||
return builder.build(); | ||
} | ||
|
||
|
||
private PUriHistogram createPUriHistogram(UriStatHistogram uriStatHistogram) { | ||
int count = uriStatHistogram.getCount(); | ||
if (uriStatHistogram.getCount() == 0) { | ||
return EMPTY_DETAILED_DATA_INSTANCE; | ||
} | ||
|
||
PUriHistogram.Builder builder = PUriHistogram.newBuilder(); | ||
|
||
long total = uriStatHistogram.getTotal(); | ||
long max = uriStatHistogram.getMax(); | ||
|
||
builder.setAvg(total / count); | ||
builder.setMax(max); | ||
|
||
int[] timestampHistograms = uriStatHistogram.getTimestampHistogram(); | ||
for (int eachTimestampHistogram : timestampHistograms) { | ||
builder.addHistogram(eachTimestampHistogram); | ||
} | ||
|
||
return builder.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.