Skip to content

Conversation

@lelenanam
Copy link
Contributor

@lelenanam lelenanam commented Dec 22, 2017

should call this to deactivate config after instance deletion

@lelenanam
Copy link
Contributor Author

Fixes weaveworks/service#1595

@bboreham
Copy link
Contributor

bboreham commented Jan 2, 2018

You need to run make update-vendor after dep commands - see https://github.com/weaveworks/cortex/blob/master/README.md#vendoring

@lelenanam lelenanam force-pushed the cleanup branch 4 times, most recently from a3a2106 to 820a5a4 Compare January 3, 2018 00:42
@bboreham
Copy link
Contributor

bboreham commented Jan 3, 2018

Now I've looked at this a bit more, it will do something slightly surprising.

The DB has potentially many configs for an instance, each with a new ID number.
DB.GetConfig() selects the non-deleted ones, limit 1 order by id DESC.

The code in this PR will mark all rows for an instance as deleted on DeactivateConfig() and mark all of them as undeleted on RestoreConfig(). So that's ok, but surprising to me.

This wouldn't play well if, for instance, some other component was marking individual rows as deleted. (Although I can't see anything like that).

Another issue is that ruler will only see the config as changed if there is one for the same instance with a higher ID number.

I'm not sure what to do about this.

#332 covers garbage-collecting old rows

@bboreham
Copy link
Contributor

bboreham commented Jan 3, 2018

There is an issue to report deleted configs - #329

Copy link
Contributor

@rndstr rndstr left a comment

Choose a reason for hiding this comment

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

just a few comments while passing by!

Copy link
Contributor

Choose a reason for hiding this comment

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

"DeactivateConfig" & same in traced.go

Copy link
Contributor

Choose a reason for hiding this comment

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

"RestoreConfig" & same in traced.go

Copy link
Contributor

Choose a reason for hiding this comment

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

return c.deletedAt.IsZero()?

Copy link
Contributor

@rndstr rndstr Jan 4, 2018

Choose a reason for hiding this comment

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

What about using WARN here? Unless DEBUG is the default level, it doesn't say that it's stalling

@lelenanam lelenanam removed the request for review from jml January 4, 2018 17:03
@bboreham
Copy link
Contributor

bboreham commented Jan 9, 2018

In regard to "ruler will only see the config as changed if there is one for the same instance with a higher ID number" - #329, Elena and I discussed IRL an idea to change the way deleted configs are interpreted.
(@lelenanam if you wrote this up somewhere I apologise; I can't find it)

At present, the DB queries fetch the last active (non-deleted) config. So you can revert from the latest config to the one before by setting deleted_at on one row. We don't know of any code that does this.

The code that updates ruler has a note of the highest ID number it has seen, and polls looking for active configs with higher numbers. So it will never report a deleted row, new or otherwise.

Suppose we change the behaviour to return the config with the highest ID, deleted or not. Then we can implement "delete a config" by adding a single new row with deleted_at set. Ruler would be notified of this new row; it would have to be enhanced to tell the difference between active and deleted configs.

If we wanted a 'revert to previous' feature, it would now be implemented by adding a new row with the previous config.

cc @jml @tomwilkie

@lelenanam
Copy link
Contributor Author

Changed deactivation as @bboreham described (add new config row with deletedAt).
But we also need extra code to stop receiving alerts.

@lelenanam
Copy link
Contributor Author

@bboreham PTAL

Copy link
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

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

Good overall: I think you'd have to change ruler to inspect DeletedAt before this could be merged.
And at least make an issue to make any other users of the data (GUIs, ...) aware that they can now receive deleted records.

Config Config `json:"config"`
ID ID `json:"id"`
Config Config `json:"config"`
DeletedAt time.Time
Copy link
Contributor

Choose a reason for hiding this comment

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

why doesn't this have a json tag?

}

// GetLastConfig gets a last configuration (active or deleted).
func (d DB) GetLastConfig(userID string) (configs.View, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a feeling this function isn't necessary: GetConfig is good enough for the purpose.

return cfgView, err
}

// SetDeletedAtConfig sets a deletedAt for configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's worth commenting why "set" is actually an "insert".

@bboreham
Copy link
Contributor

What happens in scheduler.addNewConfigs() when a deleted record update arrives in the middle of operation?

@lelenanam lelenanam force-pushed the cleanup branch 2 times, most recently from 6e27d2d to 15878d3 Compare January 31, 2018 00:26
@lelenanam
Copy link
Contributor Author

What happens in scheduler.addNewConfigs() when a deleted record update arrives in the middle of operation?

I suppose the same when config changes in the middle of the operation, this config will be updated/deleted on next scheduler.pollInterval tick.

@lelenanam
Copy link
Contributor Author

@bboreham PTAL

 - call deactivate on instance deletion
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.

4 participants