Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/139729.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 139729
summary: Suppress Azure SDK error logs
area: Snapshot/Restore
type: bug
issues: []
3 changes: 2 additions & 1 deletion modules/repository-azure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ dependencies {

implementation project(":modules:transport-netty4")
implementation("org.slf4j:slf4j-api:${versions.slf4j}")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl:${versions.log4j}")
// TODO reinstate this logging, see https://github.com/elastic/elasticsearch/pull/139729
// runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl:${versions.log4j}")

testImplementation project(':test:fixtures:azure-fixture')
yamlRestTestImplementation project(':test:fixtures:azure-fixture')
Expand Down
202 changes: 0 additions & 202 deletions modules/repository-azure/licenses/log4j-LICENSE.txt

This file was deleted.

20 changes: 0 additions & 20 deletions modules/repository-azure/licenses/log4j-NOTICE.txt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
import fixture.azure.AzureHttpHandler;
import fixture.azure.MockAzureBlobStore;

import com.azure.storage.blob.batch.BlobBatchAsyncClient;
import com.azure.storage.common.policy.RequestRetryOptions;
import com.azure.storage.common.policy.RetryPolicyType;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import org.apache.logging.log4j.Level;
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
import org.elasticsearch.cluster.metadata.ProjectId;
import org.elasticsearch.cluster.project.ProjectResolver;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Randomness;
Expand All @@ -26,6 +29,7 @@
import org.elasticsearch.common.blobstore.BlobStore;
import org.elasticsearch.common.blobstore.OperationPurpose;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.common.settings.Settings;
Expand All @@ -44,6 +48,7 @@
import org.elasticsearch.telemetry.TestTelemetryPlugin;
import org.elasticsearch.test.BackgroundIndexer;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.MockLog;
import org.elasticsearch.threadpool.ThreadPool;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -310,37 +315,74 @@ public void testLargeBlobCountDeletion() throws Exception {
}
}

public void testDeleteBlobsIgnoringIfNotExists() throws Exception {
// Test with a smaller batch size here
final int deleteBatchSize = randomIntBetween(1, 30);
final String repositoryName = randomRepositoryName();
createRepository(
repositoryName,
Settings.builder()
.put(repositorySettings(repositoryName))
.put(AzureRepository.Repository.DELETION_BATCH_SIZE_SETTING.getKey(), deleteBatchSize)
.build(),
true
public void testDeleteNonexistentBlob() throws Exception {
final var repo = asInstanceOf(
AzureRepository.class,
internalCluster().getCurrentMasterNodeInstance(RepositoriesService.class)
.repository(ProjectId.DEFAULT, createRepository(randomRepositoryName(), false))
);
try (BlobStore store = newBlobStore(repositoryName)) {
final BlobContainer container = store.blobContainer(BlobPath.EMPTY);
final int toDeleteCount = randomIntBetween(deleteBatchSize, 3 * deleteBatchSize);
final List<String> blobsToDelete = new ArrayList<>();
for (int i = 0; i < toDeleteCount; i++) {
byte[] bytes = randomBytes(randomInt(100));
String blobName = randomAlphaOfLength(10);
container.writeBlob(randomPurpose(), blobName, new BytesArray(bytes), false);
blobsToDelete.add(blobName);
final var blobContainer = repo.blobStore().blobContainer(BlobPath.EMPTY);
final var blobNames = new ArrayList<String>(10);
for (int i = 0; i < 10; i++) {
final var blobName = "test-blob-" + i + "-" + randomIdentifier();
final var contents = new BytesArray(randomAlphaOfLength(100));
blobContainer.writeBlob(randomPurpose(), blobName, contents, randomBoolean());
assertEquals(contents, Streams.readFully(blobContainer.readBlob(randomPurpose(), blobName)));
blobNames.add(blobName);
}

MockLog.assertThatLogger(() -> {
try {
blobContainer.deleteBlobsIgnoringIfNotExists(randomPurpose(), randomNonEmptySubsetOf(blobNames).iterator());
blobContainer.deleteBlobsIgnoringIfNotExists(randomPurpose(), blobNames.iterator());
} catch (Exception e) {
throw new AssertionError(e);
}
},
"com.azure.storage.blob.batch.BlobBatchAsyncClient",
new MockLog.UnseenEventExpectation("no errors", "com.azure.storage.blob.batch.BlobBatchAsyncClient", Level.ERROR, "*")
);
}

// Try to delete non existent blobs
for (int i = 0; i < 10; i++) {
blobsToDelete.add(randomName());
public void testDeleteBlobsIgnoringIfNotExists() throws Exception {
try (var mockLog = MockLog.capture(BlobBatchAsyncClient.class)) {
mockLog.addExpectation(
new MockLog.UnseenEventExpectation("no errors", BlobBatchAsyncClient.class.getCanonicalName(), Level.ERROR, "*")
);

// Test with a smaller batch size here
final int deleteBatchSize = randomIntBetween(1, 30);
final String repositoryName = randomRepositoryName();
createRepository(
repositoryName,
Settings.builder()
.put(repositorySettings(repositoryName))
.put(AzureRepository.Repository.DELETION_BATCH_SIZE_SETTING.getKey(), deleteBatchSize)
.build(),
true
);
try (BlobStore store = newBlobStore(repositoryName)) {
final BlobContainer container = store.blobContainer(BlobPath.EMPTY);
final int toDeleteCount = randomIntBetween(deleteBatchSize, 3 * deleteBatchSize);
final List<String> blobsToDelete = new ArrayList<>();
for (int i = 0; i < toDeleteCount; i++) {
byte[] bytes = randomBytes(randomInt(100));
String blobName = randomAlphaOfLength(10);
container.writeBlob(randomPurpose(), blobName, new BytesArray(bytes), false);
blobsToDelete.add(blobName);
}

// Try to delete non existent blobs
for (int i = 0; i < 10; i++) {
blobsToDelete.add(randomName());
}

Randomness.shuffle(blobsToDelete);
container.deleteBlobsIgnoringIfNotExists(randomPurpose(), blobsToDelete.iterator());
assertThat(container.listBlobs(randomPurpose()), is(anEmptyMap()));
}

Randomness.shuffle(blobsToDelete);
container.deleteBlobsIgnoringIfNotExists(randomPurpose(), blobsToDelete.iterator());
assertThat(container.listBlobs(randomPurpose()), is(anEmptyMap()));
mockLog.assertAllExpectationsMatched();
}
}

Expand Down