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

Fixes #10439 - Made trends:reduce task idempotent #2379

Closed
wants to merge 1 commit into from

Conversation

ShimShtein
Copy link
Member

Made sure that the task can run multiple times without damaging the system, and it knows how to deal with data points that were added after the original data has already migrated.

@domcleal
Copy link
Contributor

Am I missing something here? I only see tests, no change.

@ShimShtein
Copy link
Member Author

@domcleal That's because my code is awesome :) I have added the tests, but they didn't fail. That means that I have already covered these use cases.
I have left the tests, because they are describing the feature better.

@domcleal
Copy link
Contributor

Ok, so it's just adding tests and not actually making it idempotent.

How is this intended to be used? It's unclear to me from the original ticket.

@unorthodoxgeek
Copy link
Member

@ShimShtein first, be careful, you are starting to sound like me. Next up you'll be using four letter words liberally, and I don't want to be a bad influence 😛
second, if you wrote tests and they passed, you are doing something wrong, and should either reconsider calling your code "awesome" or change the order you do things - write the tests first, only then make them pass.

@ShimShtein
Copy link
Member Author

@domcleal Now in a more serious tone:
The task is the migration process that converts trends data from points format to intervals format.
I have put it in the task, so as a user you will be able to run it multiple times in order to be able not to stop reporting procedure while the task is migrating your data.

@domcleal
Copy link
Contributor

Who runs the task? It isn't configured as a cronjob in our packages, called from a DB migration to my knowledge, or documented. Should be called regularly, or only during upgrade from 1.8 to 1.9?

@@ -6,6 +6,7 @@ class TrendsTest < ActiveSupport::TestCase
Rake.application.rake_require 'tasks/trends'
Rake::Task.define_task(:environment)
Rake::Task['trends:reduce'].reenable
Rake::Task['trends:clean'].reenable
Copy link
Member

Choose a reason for hiding this comment

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

i thought we wanted to get rid of the clean task? is it needed anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll put it in a different PR. Without this line the tests will fail.

@domcleal
Copy link
Contributor

@domcleal see https://github.com/theforeman/foreman/blob/develop/db/migrate/20150202094307_add_range_to_trend_counters.rb#L6

Okay, I missed that. The issue description says it should be moved to migrations - should it?

@ohadlevy
Copy link
Member

I think it make sense to keep it, in the scenario you still collect new trends counters while the migration is working, one can rerun the task to clear up any new data points.

also useful in case you have multiple foreman running, and you upgrade them one by one or other non standard usage cases..

@ShimShtein
Copy link
Member Author

For simple scenarios it should run only once in the migration. But PR #2365 pointed out a use case when there is more than one writer to a single DB.
The task itself does not maintain a single transaction for all trends, so if the task stops in the middle for some reason, it will be able to resume without corrupting the data.

@domcleal
Copy link
Contributor

Merged as c27e0f6, thanks @ShimShtein.

@domcleal domcleal closed this May 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants