Skip to content
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

Bucket name from placeholder #363

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rmontenegroo
Copy link

@rmontenegroo rmontenegroo commented Dec 19, 2020

This patch allows the use of placeholders to setup bucket names.

There is a new parameter s3_bucket_fallback to use in cases when at least one placeholder is not found amoung chunk keys.

@rmontenegroo rmontenegroo force-pushed the bucket-name-from-placeholder branch 2 times, most recently from 0fd013d to 701911b Compare December 19, 2020 23:43
bucket_name = nil

if @s3_bucket =~ /\$\{.*\}/
@s3_bucket.scan(/\$\{([^\$\{\}]+)\}/) do |placeholder|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time placeholders does not use $ character.
We can use Validator class instead.
https://github.com/fluent/fluentd/blob/master/lib/fluent/plugin/output.rb#L607

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !@tag_placeholders.empty? || !@keys_placeholders.empty? || !@time_placeholders.empty?

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag, time and keys placeholders are scanned on @s3_bucket on star. If they're empty, the bucket is created during the star and anytime else in the future.

On the other way, if placeholders are found in @s3_bucket, it means bucket object must be evaluated, everything time before a buffer flush. This is done inside the write method. In the write method I check this situation evaluating whether @bucket is instantiated or not.

@rmontenegroo
Copy link
Author

@cosmo0920 why get_placeholders_time does not return any time placeholder if I set @s3_bucket to "test-%Y" for example?
If I set @s3_bucket = "test-%Y-%m-%d" get_placeholders_time return only %d.

@rmontenegroo
Copy link
Author

The thing is PlaceholderValidator does not allow a timekey larger than a day (https://github.com/fluent/fluentd/blob/master/lib/fluent/plugin/output.rb#L686) so it won't be possible to validate time placeholders for year and month using the validator. Am I right? Something like "test-%Y-%m" won't be accepted by validator as placeholders.

@rmontenegroo
Copy link
Author

@cosmo0920 I implemented a simple ext_get_placeholders_time only to check if there are time markers (%Y %m %d %H %M %S) in a string. With this I am able to check time placeholders, and with Validator class I can check tag and keys placeholders. I hope it is satisfying.

@cosmo0920
Copy link
Contributor

The thing is PlaceholderValidator does not allow a timekey larger than a day (https://github.com/fluent/fluentd/blob/master/lib/fluent/plugin/output.rb#L686) so it won't be possible to validate time placeholders for year and month using the validator. Am I right?

Right.

@@ -427,7 +427,7 @@ def setup_mocks(exists_return = false)
mock(Aws::S3::Client).new(anything).at_least(0) { @s3_client }
@s3_resource = mock(Aws::S3::Resource.new(client: @s3_client))
mock(Aws::S3::Resource).new(client: @s3_client) { @s3_resource }
@s3_bucket = mock(Aws::S3::Bucket.new(name: "test",
@s3_bucket = mock(Aws::S3::Bucket.new(name: "test_bucket",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change is needed?
To get merged this PR, we should add placeholders testcases.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I sincerely don't know. I thought someone changed it last patch. It was producing an error on tests I guess. I will check it later.

Yeah... I was afraid you would say that about testing placeholders. I truly have no idea how to do it right now since they're evaluated during plug-in execution time.

Any suggestions? If someone give a hint I might get through it. I am no expert on ruby tests though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... I was afraid you would say that about testing placeholders. I truly have no idea how to do it right now since they're evaluated during plug-in execution time.

These testcases are fluent-plugin-elasticsearch's but they shows how to write placeholders testcases:
https://github.com/uken/fluent-plugin-elasticsearch/blob/c0a4713edfc620cf566ede02f0f85930d1c5a88a/test/plugin/test_out_elasticsearch.rb#L3893

  • Write configuration which includes <buffer attributes1, attributes2, ..., attributesN> with Fluent::Config::Element.new and using tag/time/user defined(variables) placeholders
  • Creates chunk metadata keys which are originated from <buffer attributes1, attributes2, ..., attributesN> (This is automatically created when use test driver#feed)
  • Assert placeholders replaced values with test-unit assertions

Copy link
Contributor

@cosmo0920 cosmo0920 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use !, &&, and || instead of not, and, and or operator.
This is because symbol versions are higher precedence than not, and, and or operators. This is some pitfall of Ruby.
https://ruby-doc.org/core-2.4.0/doc/syntax/precedence_rdoc.html

lib/fluent/plugin/out_s3.rb Outdated Show resolved Hide resolved
lib/fluent/plugin/out_s3.rb Outdated Show resolved Hide resolved
lib/fluent/plugin/out_s3.rb Outdated Show resolved Hide resolved
lib/fluent/plugin/out_s3.rb Outdated Show resolved Hide resolved
lib/fluent/plugin/out_s3.rb Outdated Show resolved Hide resolved
lib/fluent/plugin/out_s3.rb Outdated Show resolved Hide resolved
lib/fluent/plugin/out_s3.rb Outdated Show resolved Hide resolved
lib/fluent/plugin/out_s3.rb Outdated Show resolved Hide resolved
Signed-off-by: rmontenegroo <montenegro.r@gmail.com>
@github-actions
Copy link

github-actions bot commented Jul 6, 2021

This PR has been automatically marked as stale because it has been open 90 days with no activity. Remove stale label or comment or this PR will be closed in 30 days

@github-actions
Copy link

github-actions bot commented Oct 6, 2021

This PR has been automatically marked as stale because it has been open 90 days with no activity. Remove stale label or comment or this PR will be closed in 30 days

@github-actions github-actions bot added the stale label Oct 6, 2021
@kenhys kenhys removed the stale label Oct 7, 2021
@github-actions
Copy link

github-actions bot commented Jan 5, 2022

This PR has been automatically marked as stale because it has been open 90 days with no activity. Remove stale label or comment or this PR will be closed in 30 days

@github-actions github-actions bot added the stale label Jan 5, 2022
@ashie ashie added enhancement and removed stale labels Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants