Skip to content

Commit d9ed807

Browse files

File tree

12 files changed

+2045
-23
lines changed

12 files changed

+2045
-23
lines changed

oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureBlobContainerProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,12 @@ public String generateUserDelegationKeySignedSas(BlockBlobClient blobClient,
203203
BlobServiceSasSignatureValues serviceSasSignatureValues,
204204
OffsetDateTime expiryTime) {
205205

206+
AzureHttpRequestLoggingPolicy loggingPolicy = new AzureHttpRequestLoggingPolicy();
207+
206208
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
207209
.endpoint(String.format(String.format("https://%s.%s", accountName, DEFAULT_ENDPOINT_SUFFIX)))
208210
.credential(getClientSecretCredential())
211+
.addPolicy(loggingPolicy)
209212
.buildClient();
210213
OffsetDateTime startTime = OffsetDateTime.now(ZoneOffset.UTC);
211214
UserDelegationKey userDelegationKey = blobServiceClient.getUserDelegationKey(startTime, expiryTime);
@@ -228,10 +231,13 @@ private ClientSecretCredential getClientSecretCredential() {
228231
@NotNull
229232
private BlobContainerClient getBlobContainerFromServicePrincipals(String accountName, RequestRetryOptions retryOptions) {
230233
ClientSecretCredential clientSecretCredential = getClientSecretCredential();
234+
AzureHttpRequestLoggingPolicy loggingPolicy = new AzureHttpRequestLoggingPolicy();
235+
231236
return new BlobContainerClientBuilder()
232237
.endpoint(String.format(String.format("https://%s.%s", accountName, DEFAULT_ENDPOINT_SUFFIX)))
233238
.credential(clientSecretCredential)
234239
.retryOptions(retryOptions)
240+
.addPolicy(loggingPolicy)
235241
.buildClient();
236242
}
237243

oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureBlobStoreBackend.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public void addMetadataRecord(File input, String name) throws DataStoreException
495495
}
496496

497497
private BlockBlobClient getMetaBlobClient(String name) throws DataStoreException {
498-
return getAzureContainer().getBlobClient(AzureConstants.AZUre_BlOB_META_DIR_NAME + "/" + name).getBlockBlobClient();
498+
return getAzureContainer().getBlobClient(AzureConstants.AZURE_BlOB_META_DIR_NAME + "/" + name).getBlockBlobClient();
499499
}
500500

501501
private void addMetadataRecordImpl(final InputStream input, String name, long recordLength) throws DataStoreException {
@@ -559,7 +559,7 @@ public List<DataRecord> getAllMetadataRecords(String prefix) {
559559
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
560560

561561
ListBlobsOptions listBlobsOptions = new ListBlobsOptions();
562-
listBlobsOptions.setPrefix(AzureConstants.AZUre_BlOB_META_DIR_NAME);
562+
listBlobsOptions.setPrefix(AzureConstants.AZURE_BlOB_META_DIR_NAME);
563563

564564
for (BlobItem blobItem : getAzureContainer().listBlobs(listBlobsOptions, null)) {
565565
BlobClient blobClient = getAzureContainer().getBlobClient(blobItem.getName());
@@ -623,7 +623,7 @@ public void deleteAllMetadataRecords(String prefix) {
623623
int total = 0;
624624

625625
ListBlobsOptions listBlobsOptions = new ListBlobsOptions();
626-
listBlobsOptions.setPrefix(AzureConstants.AZUre_BlOB_META_DIR_NAME);
626+
listBlobsOptions.setPrefix(AzureConstants.AZURE_BlOB_META_DIR_NAME);
627627

628628
for (BlobItem blobItem : getAzureContainer().listBlobs(listBlobsOptions, null)) {
629629
BlobClient blobClient = getAzureContainer().getBlobClient(blobItem.getName());

oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ public final class AzureConstants {
152152
/**
153153
* Directory name for storing metadata files in the blob storage
154154
*/
155-
public static final String AZUre_BlOB_META_DIR_NAME = "META";
155+
public static final String AZURE_BlOB_META_DIR_NAME = "META";
156156

157157
/**
158158
* Key prefix for metadata entries, includes trailing slash for directory structure
159159
*/
160-
public static final String AZURE_BLOB_META_KEY_PREFIX = AZUre_BlOB_META_DIR_NAME + "/";
160+
public static final String AZURE_BLOB_META_KEY_PREFIX = AZURE_BlOB_META_DIR_NAME + "/";
161161

162162
/**
163163
* Key name for storing blob reference information
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage;
20+
21+
import com.azure.core.http.HttpPipelineCallContext;
22+
import com.azure.core.http.HttpPipelineNextPolicy;
23+
import com.azure.core.http.HttpResponse;
24+
import com.azure.core.http.policy.HttpPipelinePolicy;
25+
import org.apache.jackrabbit.oak.commons.time.Stopwatch;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
import reactor.core.publisher.Mono;
29+
30+
import java.util.concurrent.TimeUnit;
31+
32+
/**
33+
* HTTP pipeline policy for logging Azure Blob Storage requests in the oak-blob-cloud-azure module.
34+
*
35+
* This policy logs HTTP request details including method, URL, status code, and duration.
36+
* Verbose logging can be enabled by setting the system property:
37+
* -Dblob.azure.http.verbose.enabled=true
38+
*
39+
* This is similar to the AzureHttpRequestLoggingPolicy in oak-segment-azure but specifically
40+
* designed for the blob storage operations in oak-blob-cloud-azure.
41+
*/
42+
public class AzureHttpRequestLoggingPolicy implements HttpPipelinePolicy {
43+
44+
private static final Logger log = LoggerFactory.getLogger(AzureHttpRequestLoggingPolicy.class);
45+
46+
private final boolean verboseEnabled = Boolean.getBoolean("blob.azure.http.verbose.enabled");
47+
48+
@Override
49+
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
50+
Stopwatch stopwatch = Stopwatch.createStarted();
51+
52+
return next.process().flatMap(httpResponse -> {
53+
if (verboseEnabled) {
54+
log.info("HTTP Request: {} {} {} {}ms",
55+
context.getHttpRequest().getHttpMethod(),
56+
context.getHttpRequest().getUrl(),
57+
httpResponse.getStatusCode(),
58+
(stopwatch.elapsed(TimeUnit.NANOSECONDS))/1_000_000);
59+
}
60+
61+
return Mono.just(httpResponse);
62+
});
63+
}
64+
}

oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/Utils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ public static BlobContainerClient getBlobContainer(@NotNull final String connect
5252
@Nullable final RequestRetryOptions retryOptions,
5353
final Properties properties) throws DataStoreException {
5454
try {
55+
AzureHttpRequestLoggingPolicy loggingPolicy = new AzureHttpRequestLoggingPolicy();
56+
5557
BlobServiceClientBuilder builder = new BlobServiceClientBuilder()
5658
.connectionString(connectionString)
57-
.retryOptions(retryOptions);
59+
.retryOptions(retryOptions)
60+
.addPolicy(loggingPolicy);
5861

5962
HttpClient httpClient = new NettyAsyncHttpClientBuilder()
6063
.proxy(computeProxyOptions(properties))
@@ -137,9 +140,12 @@ public static String getConnectionString(final String accountName, final String
137140
}
138141

139142
public static BlobContainerClient getBlobContainerFromConnectionString(final String azureConnectionString, final String containerName) {
143+
AzureHttpRequestLoggingPolicy loggingPolicy = new AzureHttpRequestLoggingPolicy();
144+
140145
return new BlobContainerClientBuilder()
141146
.connectionString(azureConnectionString)
142147
.containerName(containerName)
148+
.addPolicy(loggingPolicy)
143149
.buildClient();
144150
}
145151

oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/v8/AzureBlobStoreBackendV8.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import static org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureConstants.AZURE_BLOB_MAX_CONCURRENT_REQUEST_COUNT;
2828
import static org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureConstants.AZURE_BLOB_MAX_MULTIPART_UPLOAD_PART_SIZE;
2929
import static org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureConstants.AZURE_BLOB_MAX_SINGLE_PUT_UPLOAD_SIZE;
30-
import static org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureConstants.AZUre_BlOB_META_DIR_NAME;
30+
import static org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureConstants.AZURE_BlOB_META_DIR_NAME;
3131
import static org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureConstants.AZURE_BLOB_META_KEY_PREFIX;
3232
import static org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureConstants.AZURE_BLOB_MIN_MULTIPART_UPLOAD_PART_SIZE;
3333
import static org.apache.jackrabbit.oak.blob.cloud.azure.blobstorage.AzureConstants.AZURE_BLOB_REF_KEY;
@@ -329,17 +329,14 @@ public void write(DataIdentifier identifier, File file) throws DataStoreExceptio
329329
BlobRequestOptions options = new BlobRequestOptions();
330330
options.setConcurrentRequestCount(concurrentRequestCount);
331331
boolean useBufferedStream = len < AZURE_BLOB_BUFFERED_STREAM_THRESHOLD;
332-
final InputStream in = useBufferedStream ? new BufferedInputStream(new FileInputStream(file)) : new FileInputStream(file);
333-
try {
334-
blob.upload(in, len, null, options, null);
335-
LOG.debug("Blob created. identifier={} length={} duration={} buffered={}", key, len, (System.currentTimeMillis() - start), useBufferedStream);
336-
if (LOG_STREAMS_UPLOAD.isDebugEnabled()) {
337-
// Log message, with exception so we can get a trace to see where the call came from
338-
LOG_STREAMS_UPLOAD.debug("Binary uploaded to Azure Blob Storage - identifier={}", key, new Exception());
339-
}
340-
} finally {
341-
in.close();
332+
try (InputStream in = useBufferedStream ? new BufferedInputStream(new FileInputStream(file)) : new FileInputStream(file)) {
333+
blob.upload(in, len, null, options, null);
334+
LOG.debug("Blob created. identifier={} length={} duration={} buffered={}", key, len, (System.currentTimeMillis() - start), useBufferedStream);
335+
if (LOG_STREAMS_UPLOAD.isDebugEnabled()) {
336+
// Log message, with exception so we can get a trace to see where the call came from
337+
LOG_STREAMS_UPLOAD.debug("Binary uploaded to Azure Blob Storage - identifier={}", key, new Exception());
342338
}
339+
}
343340
return;
344341
}
345342

@@ -554,7 +551,7 @@ public void addMetadataRecord(File input, String name) throws DataStoreException
554551

555552
private void addMetadataRecordImpl(final InputStream input, String name, long recordLength) throws DataStoreException {
556553
try {
557-
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(AZUre_BlOB_META_DIR_NAME);
554+
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(AZURE_BlOB_META_DIR_NAME);
558555
CloudBlockBlob blob = metaDir.getBlockBlobReference(name);
559556
addLastModified(blob);
560557
blob.upload(input, recordLength);
@@ -575,7 +572,7 @@ public DataRecord getMetadataRecord(String name) {
575572
try {
576573
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
577574

578-
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(AZUre_BlOB_META_DIR_NAME);
575+
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(AZURE_BlOB_META_DIR_NAME);
579576
CloudBlockBlob blob = metaDir.getBlockBlobReference(name);
580577
if (!blob.exists()) {
581578
LOG.warn("Trying to read missing metadata. metadataName={}", name);
@@ -617,7 +614,7 @@ public List<DataRecord> getAllMetadataRecords(String prefix) {
617614
try {
618615
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
619616

620-
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(AZUre_BlOB_META_DIR_NAME);
617+
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(AZURE_BlOB_META_DIR_NAME);
621618
for (ListBlobItem item : metaDir.listBlobs(prefix)) {
622619
if (item instanceof CloudBlob) {
623620
CloudBlob blob = (CloudBlob) item;
@@ -686,7 +683,7 @@ public void deleteAllMetadataRecords(String prefix) {
686683
try {
687684
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
688685

689-
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(AZUre_BlOB_META_DIR_NAME);
686+
CloudBlobDirectory metaDir = getAzureContainer().getDirectoryReference(AZURE_BlOB_META_DIR_NAME);
690687
int total = 0;
691688
for (ListBlobItem item : metaDir.listBlobs(prefix)) {
692689
if (item instanceof CloudBlob) {

0 commit comments

Comments
 (0)