Skip to content

Small HA tracker cleanup #3808

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 10 commits into from
Feb 11, 2021
Merged

Small HA tracker cleanup #3808

merged 10 commits into from
Feb 11, 2021

Conversation

pstibrany
Copy link
Contributor

@pstibrany pstibrany commented Feb 10, 2021

What this PR does: This PR does some small code "cleanup" in HA tracker (metrics as fields, logger), and tests (removes usage of mtime, uses test.Poll). In addition to that, there is new integration test which doesn't verify behaviour, only logs it -- it shows differences in WatchPrefix and Delete behaviour between Consul (existing keys are returned via WatchPrefix, Delete doesn't send "notification" to WatchPrefix) and etcd (existing keys are not returned via WatchPrefix, but Delete "sends" notification).

Checklist

  • Tests updated
  • [na] Documentation added
  • [na] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
@pstibrany pstibrany changed the title HA tracker refactor Small HA tracker cleanup Feb 10, 2021
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
@pstibrany pstibrany mentioned this pull request Feb 10, 2021
3 tasks
ctx, cancel = context.WithTimeout(ctxUser2, time.Second)
err = checkReplicaTimestamp(ctx, c, user, cluster, replica, start)
cancel()
err = c.checkReplica(context.Background(), user, cluster, replica, now)
Copy link
Contributor

Choose a reason for hiding this comment

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

We're not passing a different user here. The test is supposed to test the HA tracker with different users. I'm a bit puzzled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, good catch. I'm bit puzzled as well... I don't think old test was really doing what the test name says. I'll update it to do so.

require.NoError(t, err)

// Stop the watcher
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

If we cancel immediately there's no guarantee the WatchPrefix() has actually had the time to receive the update. I think we should wait "a bit".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, and it's fixed in #3809, but let's add a wait here.

require.NoError(t, err, "object could not be created")

// Now delete it
err = client.Delete(context.Background(), "key-to-delete")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a sleep between creating the key-to-delete and deleting it? I'm wondering what happens if the two operations happens very close each other: the watcher may not get any notification (depending on how the backend is implemented).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, let's do that.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
@pstibrany
Copy link
Contributor Author

Thanks for reviews, I've addressed your feedbacks, please take a look again.

Copy link
Contributor

@jtlisi jtlisi left a comment

Choose a reason for hiding this comment

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

LGTM

Modulo %s/util_log.Logger/log.NewNopLogger()/g

Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM (modulo the comments about the nooplogger in tests).

I haven't checked, but if the pkg/distributor is not using the global logger anymore than please add it to the failling "rule" in Makefile:

	faillint -paths "github.com/cortexproject/cortex/pkg/util/log.{Logger}" \
		./pkg/ingester/... \
		./pkg/flusher/... \
		./pkg/distributor/... 

@pstibrany
Copy link
Contributor Author

LGTM (modulo the comments about the nooplogger in tests).

I haven't checked, but if the pkg/distributor is not using the global logger anymore than please add it to the failling "rule" in Makefile:

We're not quite there yet due to logger in (*RingConfig).RegisterFlags but I would leave that for another PR. Distributor itself is now global-logger free though.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
@pstibrany pstibrany merged commit b135d89 into cortexproject:master Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants