Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 67ff869

Browse files
committed
Address PR feedback
1 parent 240e5ba commit 67ff869

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ And then execute:
2525
<match pattern>
2626
type azure-storage-append-blob
2727

28-
azure_storage_account <your azure storage account>
29-
azure_storage_access_key <your azure storage access key> # leave empty to use MSI
30-
azure_storage_sas_token <your azure storage sas token> # leave empty to use MSI
31-
azure_container <your azure storage container>
32-
auto_create_container true
33-
path logs/
34-
azure_object_key_format %{path}%{time_slice}_%{index}.log
35-
time_slice_format %Y%m%d-%H
28+
azure_storage_account <your azure storage account>
29+
azure_storage_access_key <your azure storage access key> # leave empty to use MSI
30+
azure_storage_sas_token <your azure storage sas token> # leave empty to use MSI
31+
azure_imds_api_version <Azure Instance Metadata Service API Version> # only used for MSI
32+
azure_token_refresh_interval <refresh interval in min> # only used for MSI
33+
azure_container <your azure storage container>
34+
auto_create_container true
35+
path logs/
36+
azure_object_key_format %{path}%{time_slice}_%{index}.log
37+
time_slice_format %Y%m%d-%H
3638
# if you want to use %{tag} or %Y/%m/%d/ like syntax in path / azure_blob_name_format,
3739
# need to specify tag for %{tag} and time for %Y/%m/%d in <buffer> argument.
3840
<buffer tag,time>
@@ -55,7 +57,21 @@ This also can be retrieved from Azure Management portal.
5557

5658
If both are empty, the plugin will use the local Managed Identity endpoint to obtain a token for the target storage account.
5759

58-
### azure_container (Required)
60+
### `azure_imds_api_version` (Optional, only for MSI)
61+
62+
Default: 2019-08-15
63+
64+
The Instance Metadata Service is used during the OAuth flow to obtain an access token. This API is versioned and specifying the version is mandatory.
65+
66+
See [here](https://docs.microsoft.com/en-us/azure/virtual-machines/linux/instance-metadata-service#versioning) for more details.
67+
68+
### `azure_token_refresh_interval` (Optional, only for MSI)
69+
70+
Default: 60 (1 hour)
71+
72+
When using MSI, the initial access token needs to be refreshed periodically.
73+
74+
### `azure_container` (Required)
5975

6076
Azure Storage Container name
6177

lib/fluent/plugin/out_azure-storage-append-blob.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class AzureStorageAppendBlobOut < Fluent::Plugin::Output
2424
config_param :azure_storage_access_key, :string, default: nil, secret: true
2525
config_param :azure_storage_sas_token, :string, default: nil, secret: true
2626
config_param :azure_container, :string, default: nil
27+
config_param :azure_imds_api_version, :string, default: '2019-08-15'
28+
config_param :azure_token_refresh_interval, :integer, default: 60
2729
config_param :use_msi, :bool, default: false
2830
config_param :azure_object_key_format, :string, default: '%{path}%{time_slice}-%{index}.log'
2931
config_param :auto_create_container, :bool, default: true
@@ -73,7 +75,7 @@ def multi_workers_ready?
7375

7476
def get_access_token
7577
access_key_request = Faraday.new('http://169.254.169.254/metadata/identity/oauth2/token?' \
76-
'api-version=2019-08-15' \
78+
"api-version=#{@azure_imds_api_version}" \
7779
'&resource=https://storage.azure.com/',
7880
headers: { 'Metadata' => 'true' })
7981
.get
@@ -88,15 +90,13 @@ def start
8890
token_signer = Azure::Storage::Common::Core::Auth::TokenSigner.new token_credential
8991
@bs = Azure::Storage::Blob::BlobService.new(storage_account_name: @azure_storage_account, signer: token_signer)
9092

91-
# Refresh interval is 50 minutes
92-
refresh_interval = 50 * 60
93-
# The user-defined thread that renews the access token
93+
refresh_interval = @azure_token_refresh_interval * 60
9494
cancelled = false
9595
renew_token = Thread.new do
9696
Thread.stop
9797
until cancelled
9898
sleep(refresh_interval)
99-
# Update the access token to the credential
99+
100100
token_credential.renew_token get_access_token
101101
end
102102
end

test/plugin/test_out_azure_storage_append_blob.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class AzureStorageAppendBlobOutTest < Test::Unit::TestCase
1919
MSI_CONFIG = %(
2020
azure_storage_account test_storage_account
2121
azure_container test_container
22+
azure_imds_api_version 1970-01-01
23+
azure_token_refresh_interval 120
2224
time_slice_format %Y%m%d-%H
2325
path log
2426
).freeze
@@ -56,6 +58,8 @@ def create_driver(conf = CONFIG)
5658
assert_equal true, d.instance.use_msi
5759
assert_equal true, d.instance.auto_create_container
5860
assert_equal '%{path}%{time_slice}-%{index}.log', d.instance.azure_object_key_format
61+
assert_equal 120, d.instance.azure_token_refresh_interval
62+
assert_equal '1970-01-01', d.instance.azure_imds_api_version
5963
end
6064
end
6165

0 commit comments

Comments
 (0)