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

Storage: Read desired mode from config instead of feature flags #88353

Merged
merged 8 commits into from
May 31, 2024

Conversation

suntala
Copy link
Contributor

@suntala suntala commented May 27, 2024

What is this feature?

Read desired dual writing mode from config rather than feature toggles. Counterpart to https://github.com/grafana/grafana-enterprise/pull/6689

Why do we need this feature?

Addresses this PR comment: #87668 (comment)

Who is this feature for?

U.S. users, devs

Which issue(s) does this PR fix?:

Relates to https://github.com/grafana/search-and-storage-team/issues/15

Special notes for your reviewer:

  • Didn't find a way to directly pass in the desired mode for a given entity/builder to InstallAPIs. This is because InstallAPIs isn't in the scope of any specific builder. Would be interested in hearing suggestions for approaching this part differently.
  • I suggest removing the Grafana feature flags in a separate PR once we merge this PR. I prefer to make feature flags separately because they often lead to merge conflicts.

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@suntala suntala added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels May 27, 2024
@grafana-delivery-bot grafana-delivery-bot bot added this to the 11.1.x milestone May 27, 2024
@suntala suntala force-pushed the suntala/set-mode-using-config branch 4 times, most recently from d8fc6d1 to 0448adf Compare May 27, 2024 19:48
@suntala suntala marked this pull request as ready for review May 27, 2024 19:53
@suntala suntala requested review from a team as code owners May 27, 2024 19:53
@suntala suntala force-pushed the suntala/set-mode-using-config branch from 0448adf to 1462e7f Compare May 28, 2024 07:48
pkg/apiserver/rest/dualwriter.go Show resolved Hide resolved
pkg/apiserver/rest/dualwriter.go Show resolved Hide resolved
pkg/apiserver/rest/dualwriter.go Show resolved Hide resolved
// Get the desired dual writing mode. These are modes 1, 2, 3 and 4 if
// the feature flag `unifiedStorage` is enabled and mode 0 if it is not enabled.
// #TODO add type for map[string]grafanarest.DualWriterMode?
GetDesiredDualWriterMode(dualWrite bool, modeMap map[string]grafanarest.DualWriterMode) grafanarest.DualWriterMode
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have the key of the map be something like (Group, Resource)? Just to make sure we use all qualified names and there are no second ways to refer to the same thing. Example: ("playlist.grafana.app", "playlists") or could be in JSON format: {"group": "playlist.grafana.app", "resource": "playlists"}, or a URL (but I don't recall how they are built to give an example, sorry). Anything would work, I would just like to have a consistent way to refer to the resource that we set the dual writing mode for. IMO we don't care about the version, and that would complicate further, so we can skip that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

good call-out, in k8s a GroupResource is represented as <resource>.<group> when written as a string, though that can be confusing so using something more like a url path representation <group>/<resource> would also make sense to me (and is unambiguous because the forward slash is not an allowed character in either group or resource, while dot is a legal character in group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed it here 0ae476a. Thank you both for the suggestions!

@suntala suntala requested a review from a team as a code owner May 29, 2024 06:10
@@ -80,7 +79,8 @@ type DualWriter interface {
type DualWriterMode int

const (
Mode1 DualWriterMode = iota + 1
Mode0 DualWriterMode = iota
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make sure this still works when mode is set to 0?
I'm afraid we will end up in a weird situation id DW mode is 0 and we inevitably call NewDualWrite with no option for 0.

I wonder if it would be better to just assume if we have a dualWriterMode defined, we will have to be in one of the 4 (1-4) modes. And if it's not defined, we know we are not in the realm of any sort of dualwriter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I added integration tests for mode 0 to make sure we are taking it into account.

Mode 0 will only function as a way of representing whether unifiedStorage is enabled or not. I think this is fine because it too represents one of the dual writing states, that of not being enabled. To me dual writing doesn't have to mean literally writing to both storages. The advantage of this approach is that it allows us to simplify the signature of GetAPIGroupInfo, which was suggested in #87668 (comment). This was the best way I found to do so but happy to consider other options of course.

@suntala suntala force-pushed the suntala/set-mode-using-config branch 3 times, most recently from 6a02330 to 88cffd3 Compare May 31, 2024 11:45
@suntala suntala force-pushed the suntala/set-mode-using-config branch from 0e0c922 to d5d74e3 Compare May 31, 2024 12:43
@suntala suntala force-pushed the suntala/set-mode-using-config branch from df579f3 to d822240 Compare May 31, 2024 14:37
@suntala suntala force-pushed the suntala/set-mode-using-config branch from 0ae476a to b4b9b6d Compare May 31, 2024 15:34
@suntala suntala requested a review from grafanabot as a code owner May 31, 2024 17:04
@suntala suntala merged commit 36f4285 into main May 31, 2024
19 checks passed
@suntala suntala deleted the suntala/set-mode-using-config branch May 31, 2024 17:30
miguelmolina95 pushed a commit to miguelmolina95/grafana that referenced this pull request Jun 3, 2024
…ana#88353)

* Read desired mode from config
* Update playlist integration tests
* Add mode 1 playlist integration tests
* Add mode 0 dual writing to playlist integration tests
* Add documentation for the different dual writing modes
kminehart pushed a commit that referenced this pull request Jun 10, 2024
* Read desired mode from config
* Update playlist integration tests
* Add mode 1 playlist integration tests
* Add mode 0 dual writing to playlist integration tests
* Add documentation for the different dual writing modes
@kevinwcyu kevinwcyu modified the milestones: 11.1.x, 11.1.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend area/frontend no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes type/docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants