-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure client upgrade to allow identity options #15287
Merged
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
a77a257
Include new dependencies
georgew5656 17e7074
Mostly implemented
georgew5656 5aa991f
More azure fixes
georgew5656 dfe948b
Tests passing
georgew5656 02343d4
Unit tests running
georgew5656 70c6cf6
Test running after removing storage exception
georgew5656 d9b28eb
Happy with coverage now
georgew5656 983ff52
Add more tests
georgew5656 9aaf451
fix client factory
georgew5656 6a99496
cleanup from testing
georgew5656 ddcfc03
Remove old client
georgew5656 305eb85
update docs
georgew5656 9e84ade
Exclude from spellcheck
georgew5656 fae6fa1
Add licenses
georgew5656 c2a82fe
Fix identity version
georgew5656 43e81c5
Save work
georgew5656 9812a67
Add azure clients
georgew5656 28cbf0a
Merge branch 'master' of github.com:georgew5656/druid into azureClien…
georgew5656 12ab481
fix merge conflict
georgew5656 0f80541
add licenses
georgew5656 405310c
typos
georgew5656 7da2f4d
Add dependencies
georgew5656 13dd4d2
Merge branch 'master' of github.com:georgew5656/druid into azureClien…
georgew5656 0787dbb
Exception is not thrown
georgew5656 295db27
Fix intellij check
georgew5656 bf74260
Don't need to override
georgew5656 260d72f
specify length
georgew5656 bb72518
urldecode
georgew5656 129d3d9
encode path
georgew5656 d023f63
Fix checks
georgew5656 2c5d257
Merge branch 'master' into azureClientUpgrade
georgew5656 423d226
Revert urlencode changes
georgew5656 60a7b96
Urlencode with azure library
georgew5656 ce79b59
Update docs/development/extensions-core/azure.md
georgew5656 cfff1ee
Merge branch 'azureClientUpgrade' of github.com:georgew5656/druid int…
georgew5656 9ca19e0
PR changes
georgew5656 8133e1d
Update docs/development/extensions-core/azure.md
georgew5656 fe5758f
Deprecate AzureTaskLogsConfig.maxRetries
georgew5656 92f7535
Merge branch 'azureClientUpgrade' of github.com:georgew5656/druid int…
georgew5656 a4fa3a2
Clean up azure retry block
georgew5656 4654815
logic update to reuse clients
georgew5656 be67328
fix comments
georgew5656 292ff42
Create container conditionally
georgew5656 3dfabb3
Fix key auth
georgew5656 53f7dd7
Remove container client logic
georgew5656 daa6179
Add some more testing
georgew5656 9a069ea
Update comments
georgew5656 9f04d39
Add a comment explaining client reuse
georgew5656 6899704
Move logic to factory class
georgew5656 907c4e9
use bom for dependency management
georgew5656 8d2d3c0
fix license versions
georgew5656 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
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ore/azure-extensions/src/main/java/org/apache/druid/storage/azure/AzureClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.druid.storage.azure; | ||
|
||
import com.azure.core.http.policy.ExponentialBackoffOptions; | ||
import com.azure.core.http.policy.RetryOptions; | ||
import com.azure.identity.DefaultAzureCredentialBuilder; | ||
import com.azure.storage.blob.BlobServiceClient; | ||
import com.azure.storage.blob.BlobServiceClientBuilder; | ||
import com.azure.storage.common.StorageSharedKeyCredential; | ||
|
||
import java.time.Duration; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Factory class for generating BlobServiceClient objects. | ||
*/ | ||
public class AzureClientFactory | ||
{ | ||
|
||
private final AzureAccountConfig config; | ||
private final Map<Integer, BlobServiceClient> cachedBlobServiceClients; | ||
|
||
public AzureClientFactory(AzureAccountConfig config) | ||
{ | ||
this.config = config; | ||
this.cachedBlobServiceClients = new HashMap<>(); | ||
} | ||
|
||
// It's okay to store clients in a map here because all the configs for specifying azure retries are static, and there are only 2 of them. | ||
// The 2 configs are AzureAccountConfig.maxTries and AzureOutputConfig.maxRetrr. | ||
// We will only ever have at most 2 clients in cachedBlobServiceClients. | ||
public BlobServiceClient getBlobServiceClient(Integer retryCount) | ||
{ | ||
if (!cachedBlobServiceClients.containsKey(retryCount)) { | ||
BlobServiceClientBuilder clientBuilder = getAuthenticatedBlobServiceClientBuilder() | ||
.retryOptions(new RetryOptions( | ||
new ExponentialBackoffOptions() | ||
.setMaxRetries(retryCount != null ? retryCount : config.getMaxTries()) | ||
.setBaseDelay(Duration.ofMillis(1000)) | ||
.setMaxDelay(Duration.ofMillis(60000)) | ||
)); | ||
cachedBlobServiceClients.put(retryCount, clientBuilder.buildClient()); | ||
} | ||
|
||
return cachedBlobServiceClients.get(retryCount); | ||
} | ||
|
||
private BlobServiceClientBuilder getAuthenticatedBlobServiceClientBuilder() | ||
{ | ||
BlobServiceClientBuilder clientBuilder = new BlobServiceClientBuilder() | ||
.endpoint("https://" + config.getAccount() + ".blob.core.windows.net"); | ||
|
||
if (config.getKey() != null) { | ||
clientBuilder.credential(new StorageSharedKeyCredential(config.getAccount(), config.getKey())); | ||
} else if (config.getSharedAccessStorageToken() != null) { | ||
clientBuilder.sasToken(config.getSharedAccessStorageToken()); | ||
} else if (config.getUseAzureCredentialsChain()) { | ||
// We might not use the managed identity client id in the credential chain but we can just set it here and it will no-op. | ||
DefaultAzureCredentialBuilder defaultAzureCredentialBuilder = new DefaultAzureCredentialBuilder() | ||
.managedIdentityClientId(config.getManagedIdentityClientId()); | ||
clientBuilder.credential(defaultAzureCredentialBuilder.build()); | ||
} | ||
return clientBuilder; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add validation to error out if the user sets this without setting
useAzureCredentialsChain = true
as called out in the docs