|
| 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