Skip to content

Commit ca4858e

Browse files
authored
HADOOP-19575. ABFS: [FNSOverBlob] Add Distinct String In User Agent to Get Telemetry for FNS-Blob (#7713) (#7788)
Contributed by Manika Joshi.
1 parent 812c679 commit ca4858e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.SEMICOLON;
128128
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.SINGLE_WHITE_SPACE;
129129
import static org.apache.hadoop.fs.azurebfs.constants.AbfsHttpConstants.UTF_8;
130+
import static org.apache.hadoop.fs.azurebfs.constants.AbfsServiceType.BLOB;
130131
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_IDENTITY_TRANSFORM_CLASS;
131132
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.DEFAULT_DELETE_CONSIDERED_IDEMPOTENT;
132133
import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.ONE_MB;
@@ -152,6 +153,7 @@ public abstract class AbfsClient implements Closeable {
152153
public static final Logger LOG = LoggerFactory.getLogger(AbfsClient.class);
153154
public static final String HUNDRED_CONTINUE_USER_AGENT = SINGLE_WHITE_SPACE + HUNDRED_CONTINUE + SEMICOLON;
154155
public static final String ABFS_CLIENT_TIMER_THREAD_NAME = "abfs-timer-client";
156+
public static final String FNS_BLOB_USER_AGENT_IDENTIFIER = "FNS";
155157

156158
private final URL baseUrl;
157159
private final SharedKeyCredentials sharedKeyCredentials;
@@ -1323,6 +1325,14 @@ String initializeUserAgent(final AbfsConfiguration abfsConfiguration,
13231325
sb.append(FORWARD_SLASH);
13241326
sb.append(abfsConfiguration.getClusterType());
13251327

1328+
// Add a unique identifier in FNS-Blob user agent string
1329+
if (!getIsNamespaceEnabled()
1330+
&& abfsConfiguration.getFsConfiguredServiceType() == BLOB) {
1331+
sb.append(SEMICOLON)
1332+
.append(SINGLE_WHITE_SPACE)
1333+
.append(FNS_BLOB_USER_AGENT_IDENTIFIER);
1334+
}
1335+
13261336
sb.append(")");
13271337

13281338
appendIfNotEmpty(sb, abfsConfiguration.getCustomUserAgentPrefix(), false);

hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azurebfs/services/ITestAbfsClient.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public final class ITestAbfsClient extends AbstractAbfsIntegrationTest {
106106

107107
private static final String ACCOUNT_NAME = "bogusAccountName.dfs.core.windows.net";
108108
private static final String FS_AZURE_USER_AGENT_PREFIX = "Partner Service";
109+
private static final String FNS_BLOB_USER_AGENT_IDENTIFIER = "FNS";
109110
private static final String HUNDRED_CONTINUE_USER_AGENT = SINGLE_WHITE_SPACE + HUNDRED_CONTINUE + SEMICOLON;
110111
private static final String TEST_PATH = "/testfile";
111112
public static final int REDUCED_RETRY_COUNT = 2;
@@ -355,6 +356,42 @@ public void verifyUserAgentClusterType() throws Exception {
355356
.contains(DEFAULT_VALUE_UNKNOWN);
356357
}
357358

359+
@Test
360+
// Test to verify the unique identifier in user agent string for FNS-Blob accounts
361+
public void verifyUserAgentForFNSBlob() throws Exception {
362+
assumeHnsDisabled();
363+
assumeBlobServiceType();
364+
final AzureBlobFileSystem fs = getFileSystem();
365+
final AbfsConfiguration configuration = fs.getAbfsStore()
366+
.getAbfsConfiguration();
367+
368+
String userAgentStr = getUserAgentString(configuration, false);
369+
verifyBasicInfo(userAgentStr);
370+
Assertions.assertThat(userAgentStr)
371+
.describedAs(
372+
"User-Agent string for FNS accounts on Blob endpoint should contain "
373+
+ FNS_BLOB_USER_AGENT_IDENTIFIER)
374+
.contains(FNS_BLOB_USER_AGENT_IDENTIFIER);
375+
}
376+
377+
@Test
378+
// Test to verify that the user agent string for non-FNS-Blob accounts
379+
// does not contain the FNS identifier.
380+
public void verifyUserAgentForDFS() throws Exception {
381+
assumeDfsServiceType();
382+
final AzureBlobFileSystem fs = getFileSystem();
383+
final AbfsConfiguration configuration = fs.getAbfsStore()
384+
.getAbfsConfiguration();
385+
386+
String userAgentStr = getUserAgentString(configuration, false);
387+
verifyBasicInfo(userAgentStr);
388+
Assertions.assertThat(userAgentStr)
389+
.describedAs(
390+
"User-Agent string for non-FNS-Blob accounts should not contain"
391+
+ FNS_BLOB_USER_AGENT_IDENTIFIER)
392+
.doesNotContain(FNS_BLOB_USER_AGENT_IDENTIFIER);
393+
}
394+
358395
public static AbfsClient createTestClientFromCurrentContext(
359396
AbfsClient baseAbfsClientInstance,
360397
AbfsConfiguration abfsConfig) throws IOException, URISyntaxException {

0 commit comments

Comments
 (0)