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

CloudWatch: Deprecate dynamic labels feature toggle, remove support for Alias in backend #66494

Merged
merged 16 commits into from
Apr 27, 2023

Conversation

fridgepoet
Copy link
Member

@fridgepoet fridgepoet commented Apr 13, 2023

What is this feature?

In the backend of the CloudWatch plugin, this

  • Removes any check for the Dynamic Label feature toggle, meaning Dynamic Label can no longer be disabled
    • setting the feature toggle off (cloudWatchDynamicLabels = false) will no longer have any effect
  • Removes support for the Alias field to be used directly
  • Still migrates Alias to Dynamic Label once: The migration will be handled on the fly, and will be propagated to the dashboard json model only when the user opens the query editor. Once the user has saved the dashboard model with the migrated label value, migration won't happen again. This also applies to Alert rules.

The change of the frontend code will be in a separate PR.
The removal of the feature toggle itself will be in a separate PR.

Why do we need this feature?

This was slated for removal in Grafana 10

Which issue(s) does this PR fix?:

Contributes to #66437

Special notes for your reviewer:
Alias has been replaced by Dynamic Label in #48434

Testing notes:

Normal queries:

  • Start on the main branch with the cloudWatchDynamicLabels toggle off
[feature_toggles]
cloudWatchDynamicLabels = false
  • (Still on main branch) Create a dashboard with a CloudWatch datasource panel
  • You should see the Alias field. Enter some former Alias pattern like {{period}}
  • Save that dashboard.
  • Now you can check out this PR and restart Grafana.
  • No matter if the feature toggle is false or true, you should see no longer see the Alias field. It should now be a Label field populated with a migrated pattern, e.g. ${PROP('Period')}
    • This Label will not be saved unless the dashboard is saved.
    • Alert rules with Alias will not have their Label saved unless the rule is edited (opened and viewed) and saved again.

In alerts:

  • Create a dashboard with a CloudWatch datasource panel.
  • In the dashboard JSON model, do not include a label target in the panel yet, just use an alias target like:
      "targets": [
        {
          "alias": "{{period}}",
          "datasource": {
            "type": "cloudwatch",
            "uid": "xpyRJd9Mz"
          },
          "dimensions": {},
          "expression": "",
          "id": "",
          "logGroups": [],
          "matchExact": true,
          "metricEditorMode": 0,
          "metricName": "CPUUtilization",
          "metricQueryType": 0,
          "namespace": "AWS/EC2",
          "period": "",
          "queryMode": "Metrics",
          "refId": "A",
          "region": "default",
          "sqlExpression": "",
          "statistic": "Average"
        }
      ],

This simulates a "legacy alias" query.

  • Create an Alert based on this query.
  • With this PR, regardless of cloudWatchDynamicLabels equal to true or false, we should see requests from the Alert query being made to the GetMetricData API with label. (In this example, alias would have been migrated to label equal to ${PROP('Period')})
    • this assertion was made in unit tests and locally by spying on the value of label while running (e.g. added a log line, can also check it by debugging with a breakpoint right around here)

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.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 13, 2023

⚠️   Possible breaking changes

(Open the links below in a new tab to go to the correct steps)

grafana-data has possible breaking changes (more info)
grafana-runtime has possible breaking changes (more info)
grafana-schema has possible breaking changes (more info)

Console output
Read our guideline

@github-actions
Copy link
Contributor

github-actions bot commented Apr 13, 2023

Backend code coverage report for PR #66494

Plugin Main PR Difference
cloudwatch 82.7% 81.9% -.8%

@github-actions
Copy link
Contributor

github-actions bot commented Apr 13, 2023

Frontend code coverage report for PR #66494

Plugin Main PR Difference
cloudwatch 82.99% 82.99% 0%

@grafanabot grafanabot added the levitate breaking change A label indicating a breaking change and assigned by Levitate. label Apr 20, 2023
@fridgepoet fridgepoet changed the title CloudWatch: Remove alias and cloudWatchDynamicLabels feature toggle CloudWatch: Remove alias and check for feature boolean Apr 21, 2023
@fridgepoet fridgepoet changed the title CloudWatch: Remove alias and check for feature boolean CloudWatch: Remove alias, making dynamic labels enabled by default Apr 21, 2023
Comment on lines -90 to -92
deepLink, err := query.BuildDeepLink(startTime, endTime, false)
deepLink, err := query.BuildDeepLink(startTime, endTime)
require.NoError(t, err)
assert.NotContains(t, deepLink, "label")
Copy link
Member Author

Choose a reason for hiding this comment

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

those were written backwards from what the test name described

Comment on lines -111 to -113
deepLink, err := query.BuildDeepLink(startTime, endTime, false)
deepLink, err := query.BuildDeepLink(startTime, endTime)
require.NoError(t, err)
assert.NotContains(t, deepLink, "label")
Copy link
Member Author

Choose a reason for hiding this comment

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

those were also written backwards from what the test name described

Comment on lines 292 to 301
func TestQueryJSON(t *testing.T) {
jsonString := []byte(`{
"type": "timeSeriesQuery"
}`)
var res metricsDataQuery
err := json.Unmarshal(jsonString, &res)
require.NoError(t, err)
assert.Equal(t, "timeSeriesQuery", res.Type)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

assert.Equal(t, "lb2", frame2.Fields[1].Labels["LoadBalancer"])
})

t.Run("Expand dimension value using substring", func(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

seems to be a near-duplicate of the test above: asserts and acts on the same alias string

@@ -499,23 +249,4 @@ func TestCloudWatchResponseParser(t *testing.T) {
assert.Equal(t, "Value", frame.Fields[1].Name)
assert.Equal(t, "", frame.Fields[1].Config.DisplayName)
})

t.Run("buildDataFrames should use response label as frame name when dynamic label is enabled", func(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

should be covered in "buildDataFrames should use response label as frame name" now


t.Run("Expand dimension value using exact match", func(t *testing.T) {
func Test_buildDataFrames_uses_response_label_as_frame_name(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests used to document how the Alias was transformed:
#21541
#22695
I'm reluctant to remove them as they continue to document different input queries.

The thing they document now is pretty mundane -- now all of the resulting frame names come from the response "label" from the GetMetricData API, not from the input alias.

@fridgepoet fridgepoet marked this pull request as ready for review April 25, 2023 14:39
@fridgepoet fridgepoet requested a review from a team as a code owner April 25, 2023 14:39
@fridgepoet fridgepoet requested review from sarahzinger and removed request for a team April 25, 2023 14:39
@fridgepoet fridgepoet changed the title CloudWatch: Remove alias, making dynamic labels enabled by default CloudWatch: Remove alias, making dynamic labels enabled by default in the backend Apr 25, 2023
@fridgepoet fridgepoet added this to the 10.0.0 milestone Apr 25, 2023
@sarahzinger sarahzinger modified the milestones: 10.0.0, 10.0.x Apr 25, 2023
@fridgepoet fridgepoet marked this pull request as draft April 25, 2023 16:27
@fridgepoet fridgepoet marked this pull request as ready for review April 25, 2023 16:49
Copy link
Member

@sarahzinger sarahzinger left a comment

Choose a reason for hiding this comment

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

Kind of basic question on my part haha sorry, if the feature is enabled by default: https://github.com/grafana/grafana/blob/main/pkg/services/featuremgmt/registry.go#L124 then how does this pr make dynamic labels enabled by default? I thought it was already done? Would it be fair to reword this as removing support for alias or something like that instead?

Otherwise makes sense to me!

@fridgepoet fridgepoet changed the title CloudWatch: Remove alias, making dynamic labels enabled by default in the backend CloudWatch: Remove any check for dynamic labels feature toggle Apr 26, 2023
@fridgepoet
Copy link
Member Author

fridgepoet commented Apr 26, 2023

Good point, thanks @sarahzinger. I've removed the focus from making the dynamic labels default since you're right that was already the case.
What's happening here is that even if someone sets the feature toggle off (cloudWatchDynamicLabels = false), our plan is that this will no longer have any effect.

(Since the code will still do a one-time Alias->Label migration, I wasn't able to truly remove Alias from the code. I am working on getting the deprecated comment in.)

@fridgepoet fridgepoet changed the title CloudWatch: Remove any check for dynamic labels feature toggle CloudWatch: Remove any check for dynamic labels feature toggle, remove support for Alias field to be used directly Apr 26, 2023
@sarahzinger
Copy link
Member

sounds good maybe the title change can be something like Cloudwatch: Deprecate Alias Feature Toggle to make it easier for people to spot if they were relying on it? Totally agree we should keep the migration!

@fridgepoet fridgepoet changed the title CloudWatch: Remove any check for dynamic labels feature toggle, remove support for Alias field to be used directly CloudWatch: Start deprecating dynamic labels feature toggle, remove support for Alias Apr 26, 2023
@fridgepoet fridgepoet changed the title CloudWatch: Start deprecating dynamic labels feature toggle, remove support for Alias CloudWatch: Deprecate dynamic labels feature toggle, remove support for Alias in backend Apr 26, 2023
@fridgepoet
Copy link
Member Author

@sarahzinger I've created an issue to deprecate Alias and its migration here #67315, let me know what you think. I guess it can be in Grafana 11?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add to changelog area/backend area/frontend datasource/CloudWatch levitate breaking change A label indicating a breaking change and assigned by Levitate. no-backport Skip backport of PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants