Skip to content

Support other rufus scheduling options #183

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

Merged
merged 9 commits into from
May 30, 2025

Conversation

ash-darin
Copy link
Contributor

Allow jdbc input to be scheduled with different options supported by rufus scheduler.

Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/

Allow jdbc input to be scheduled with different options supported by rufus scheduler.
Copy link

cla-checker-service bot commented Apr 1, 2025

💚 CLA has been signed

@robbavey
Copy link
Contributor

robbavey commented Apr 3, 2025

@ash-darin Thank you for your contribution! Would you mind signing the CLA?

@ash-darin
Copy link
Contributor Author

@robbavey I'm currently clearing this with higher up.

I have to critizise that I have to provide an e-mail address before I am even allowed to read it, or is there a hidden link to the PDF somewhere?

@jsvd
Copy link
Member

jsvd commented Apr 8, 2025

@ash-darin I'll provide that feedback to the team, but just to clarify, the initial name+email form serves only to pre-fill data in the agreement docusign, after introducing the data you get full access to the agreement and the option to start the signing process itself.

[edit] on that next page you can view and download the agreement as a pdf

@ash-darin
Copy link
Contributor Author

ash-darin commented Apr 8, 2025

@jsvd on that "next page" I have to agree "to use electronic records and signatures", marked with an "*" as mandatory, or if I want to "Finish later" I have to provide an e-mail address. Otherwise I do not get access to the PDF.

@jsvd
Copy link
Member

jsvd commented Apr 8, 2025

@ash-darin right, those are docusign's own formalities on agreeing to use digital signing. if you are/your company is not comfortable agreeing to that before seeing the CLA itself I'll reach out internally to find a way to get the pdf to you first.

@ash-darin ash-darin marked this pull request as ready for review April 10, 2025 11:26
@ash-darin
Copy link
Contributor Author

Is there anything else I ought to do / observe?

@jsvd
Copy link
Member

jsvd commented Apr 23, 2025

Given .every can be implemented with a cron job (e.g. "every 3h" == 0 */3 * * *), could we maybe add only interval which is different: trigger immediately and when it's done wait "interval" before doing it again?

@ash-darin
Copy link
Contributor Author

Given .every can be implemented with a cron job (e.g. "every 3h" == 0 */3 * * *), could we maybe add only interval which is different: trigger immediately and when it's done wait "interval" before doing it again?

.every ? Maybe you mistyped and meant period?

I don't see the reason to limit us in that way, there is a use case for which period exists next to cron and interval.

period is slightly different from cron, in the sense that it runs from the moment the timer is started (logstash is started), while a cron always starts at 0 (seconds) . This difference can be advantageous if you have multiple, identically configured logstashes (as many people are prone to do with central configuration management / version management). With a cron job (and no special voodoo to randomize values) they would all trigger simultaneously (e.g. a sql query), while jobs configured with `period´ would trigger slight apart (as the logstashes would start slightly apart), though with the same repeating pattern. I had two logstashes where two cronjobs fired so precisely simultaneous that their writing to elasticsearch collided with a "version mismatch".

I would therefore ask that both, period and interval are implemented.

@jsvd
Copy link
Member

jsvd commented Apr 24, 2025

Thanks for the clarification, could I ask you to add docs for period and interval and their equivalent section to docs/input-jdbc.asciidoc?

Example:

@ash-darin
Copy link
Contributor Author

Thanks for the clarification, could I ask you to add docs for period and interval and their equivalent section to docs/input-jdbc.asciidoc?

Example:

Of course, should I do this in this PR? Or better not add to this and open a separate one?

@jsvd
Copy link
Member

jsvd commented Apr 24, 2025

I'd prefer in the same PR so the same changeset introduces the feature and its associated documentation. 🙏

@jsvd
Copy link
Member

jsvd commented Apr 28, 2025

@ash-darin thanks for the doc work! I created a PR against yours to make the exclusive nature of these settings explicit to the user ash-darin#1

ash-darin added 4 commits May 28, 2025 10:05
make scheduling option exclusivity explicit
Remove default "no error case", build fails otherwise
@ash-darin
Copy link
Contributor Author

ash-darin commented May 28, 2025

@jsvd Hi, I merged your PR but had to remove the else path as it made the build fail for reasons I could not understand. It was "just" the "ok, do nothing" path, so I think that ought to be sufficient?

See here for an example:

https://app.travis-ci.com/github/logstash-plugins/logstash-integration-jdbc/jobs/633122890

The Travis builds still fail in part but not due to anything in my PR it seems to me.

@jsvd
Copy link
Member

jsvd commented May 29, 2025

This is enough to fix it, while keeping the test:

diff --git a/spec/inputs/jdbc_spec.rb b/spec/inputs/jdbc_spec.rb
index 6085c41..4d08ccd 100755
--- a/spec/inputs/jdbc_spec.rb
+++ b/spec/inputs/jdbc_spec.rb
@@ -229,19 +229,28 @@ describe LogStash::Inputs::Jdbc do
   end
 
   describe "scheduling options" do
+    let(:settings) { super().merge("statement" => "SELECT :num_param as num_param FROM SYSIBM.SYSDUMMY1") }
     scheduling_options = ["interval", "schedule", "period"]
     scheduling_options.combination(2).each do |option1, option2|
       context "when using '#{option1}' and '#{option2}' at the same time" do
         let(:settings) { super().merge(option1 => 'a', option2 => 'b') }
         it "raises a configuration error" do
-          expect { plugin.register }.to raise_error(LogStash::ConfigurationError)
+          expect { plugin.register }.to raise_error(LogStash::ConfigurationError, /Use only one/)
         end
       end
     end
     context "when using 'schedule', 'period' and 'interval' at the same time" do
       let(:settings) { super().merge("interval" => "a", "period" => "b", "schedule" => "c") }
       it "raises a configuration error" do
-        expect { plugin.register }.to raise_error(LogStash::ConfigurationError)
+        expect { plugin.register }.to raise_error(LogStash::ConfigurationError, /Use only one/)
+      end
+    end
+    scheduling_options.each do |option|
+      context "when using only '#{option}'" do
+        let(:settings) { super().merge(option => "a") }
+        it "does not raise a configuration error" do
+          expect { plugin.register }.to_not raise_error
+        end
       end
     end
   end

Copy link
Member

@jsvd jsvd left a comment

Choose a reason for hiding this comment

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

CI failures are unrelated and due to an issue in the snapshot logstash docker images that will be fixed by tomorrow. LGTM. I'll merge and publish the PR. thanks for the contribution!

@jsvd jsvd merged commit 549c44b into logstash-plugins:main May 30, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants