Skip to content

Commit da41836

Browse files
Added new tracing class for metrics
1 parent 388d837 commit da41836

File tree

3 files changed

+63
-13
lines changed

3 files changed

+63
-13
lines changed

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsReadFooterMetrics.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919

2020
import java.util.concurrent.atomic.AtomicLong;
2121
import java.util.List;
22+
import java.util.ArrayList;
2223

2324
public class AbfsReadFooterMetrics {
2425
private boolean isParquetFile;
2526
private String sizeReadByFirstRead;
2627
private String offsetDiffBetweenFirstAndSecondRead;
27-
private AtomicLong fileLength;
28+
private final AtomicLong fileLength;
2829
private double avgFileLength;
2930

3031
public AbfsReadFooterMetrics() {
@@ -140,8 +141,8 @@ public static String getReadFooterMetrics(AbfsReadFooterMetrics avgReadFooterMet
140141
}
141142

142143
public static String getFooterMetrics(List<AbfsReadFooterMetrics> readFooterMetricsList, String readFooterMetric){
143-
List<AbfsReadFooterMetrics> isParquetList = new java.util.ArrayList<>();
144-
List<AbfsReadFooterMetrics> isNonParquetList = new java.util.ArrayList<>();
144+
List<AbfsReadFooterMetrics> isParquetList = new ArrayList<>();
145+
List<AbfsReadFooterMetrics> isNonParquetList = new ArrayList<>();
145146
for (AbfsReadFooterMetrics abfsReadFooterMetrics : readFooterMetricsList) {
146147
if (abfsReadFooterMetrics.getIsParquetFile()) {
147148
isParquetList.add(abfsReadFooterMetrics);

hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/utils/TracingContext.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,6 @@ public void constructHeader(AbfsHttpOperation httpOperation) {
174174
case TWO_ID_FORMAT:
175175
header = clientCorrelationID + ":" + clientRequestId;
176176
break;
177-
case INTERNAL_METRIC_FORMAT:
178-
String[] metric = metricResults.split("@");
179-
header = clientCorrelationID + ":" + clientRequestId + ":" + fileSystemID + ":" + "BO:" + metric[0] + "FO:" + metric[1];
180-
break;
181-
case INTERNAL_FOOTER_METRIC_FORMAT:
182-
header = clientCorrelationID + ":" + clientRequestId + ":" + fileSystemID + ":" + "FO:" + metricResults;
183-
break;
184-
case INTERNAL_BACKOFF_METRIC_FORMAT:
185-
header = clientCorrelationID + ":" + clientRequestId + ":" + fileSystemID + ":" + "BO:" + metricResults;
186-
break;
187177
default:
188178
header = clientRequestId; //case SINGLE_ID_FORMAT
189179
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.apache.hadoop.fs.azurebfs.utils;
2+
3+
import org.apache.hadoop.fs.azurebfs.services.AbfsCounters;
4+
import org.apache.hadoop.fs.azurebfs.constants.FSOperationType;
5+
import org.apache.hadoop.fs.azurebfs.services.AbfsHttpOperation;
6+
import java.util.UUID;
7+
import java.util.List;
8+
import org.apache.hadoop.fs.azurebfs.services.AbfsReadFooterMetrics;
9+
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.EMPTY_STRING;
10+
11+
public class TracingMetricContext extends TracingContext{
12+
private AbfsCounters abfsCounters;
13+
private String header = EMPTY_STRING;
14+
15+
private final String clientCorrelationID; // passed over config by client
16+
private final String fileSystemID; // GUID for fileSystem instance
17+
private String clientRequestId = EMPTY_STRING;
18+
private TracingHeaderFormat tracingHeaderFormat;
19+
20+
public TracingMetricContext(String clientCorrelationID, String fileSystemID,
21+
FSOperationType opType, boolean needsPrimaryReqId,
22+
TracingHeaderFormat tracingHeaderFormat, Listener listener,
23+
AbfsCounters abfsCounters) {
24+
super(clientCorrelationID, fileSystemID, opType, needsPrimaryReqId, tracingHeaderFormat, listener);
25+
this.clientCorrelationID = clientCorrelationID;
26+
this.fileSystemID = fileSystemID;
27+
this.tracingHeaderFormat = tracingHeaderFormat;
28+
this.abfsCounters = abfsCounters;
29+
}
30+
31+
private String getFooterMetrics(){
32+
List<AbfsReadFooterMetrics> readFooterMetricsList = abfsCounters.getAbfsReadFooterMetrics();
33+
String readFooterMetric = "";
34+
if (!readFooterMetricsList.isEmpty()) {
35+
readFooterMetric = AbfsReadFooterMetrics.getFooterMetrics(readFooterMetricsList, readFooterMetric);
36+
}
37+
return readFooterMetric;
38+
}
39+
40+
@Override
41+
public void constructHeader(AbfsHttpOperation httpOperation){
42+
clientRequestId = UUID.randomUUID().toString();
43+
switch (tracingHeaderFormat) {
44+
case INTERNAL_METRIC_FORMAT:
45+
header = clientCorrelationID + ":" + clientRequestId + ":" + fileSystemID
46+
+ ":" + "BO:" + abfsCounters.getAbfsBackoffMetrics().toString() +
47+
"FO:" + getFooterMetrics();
48+
break;
49+
case INTERNAL_FOOTER_METRIC_FORMAT:
50+
header = clientCorrelationID + ":" + clientRequestId + ":" + fileSystemID
51+
+ ":" + "FO:" + getFooterMetrics();
52+
break;
53+
case INTERNAL_BACKOFF_METRIC_FORMAT:
54+
header = clientCorrelationID + ":" + clientRequestId + ":" + fileSystemID
55+
+ ":" + "BO:" + abfsCounters.getAbfsBackoffMetrics().toString();
56+
break;
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)