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

changefeedccl: add scoping support for max_behind_nanos #137534

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

aerfrei
Copy link
Contributor

@aerfrei aerfrei commented Dec 16, 2024

Currently, changefeed.max_behind_nanos is a measurement of the
lag of the furthest behind changefeed. We'd like to be able to
support scoping/grouping changefeeds. This applies scoping to
that metric similar to the scoping on changefeed.aggregator_progress.

Epic: none
Fixes: #132281

Release note (ops change): the changefeed.max_behind_nanos metric
now supports scoping with metric labels.

Copy link

blathers-crl bot commented Dec 16, 2024

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@aerfrei aerfrei force-pushed the aerin/metrics branch 7 times, most recently from 2842954 to 611ab0c Compare December 17, 2024 19:06
@aerfrei aerfrei changed the title Aerin/metrics changefeedccl: add scoping support for max_behind_nanos Dec 17, 2024
@aerfrei aerfrei force-pushed the aerin/metrics branch 2 times, most recently from 1b644b9 to 6e1a766 Compare December 17, 2024 21:51
@aerfrei aerfrei marked this pull request as ready for review December 17, 2024 21:52
@aerfrei aerfrei requested review from a team as code owners December 17, 2024 21:52
@aerfrei aerfrei requested review from xinhaoz, arjunmahishi, aa-joshi, rharding6373, asg0451 and andyyang890 and removed request for a team December 17, 2024 21:52
Copy link
Collaborator

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 3 files at r1, 2 of 3 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @aa-joshi, @aerfrei, @arjunmahishi, @asg0451, @rharding6373, and @xinhaoz)


-- commits line 9 at r2:
FYI it's not necessary to put an Epic if you've already linked an issue (linking an issue is preferred per https://cockroachlabs.atlassian.net/wiki/spaces/CRDB/pages/2009039063/Issue+and+Epic+Refs+in+Commits+and+PRs)


pkg/ccl/changefeedccl/metrics.go line 1003 at r2 (raw file):

		var max int64
		for _, val := range childValues {
			if val != 0 && val > max {

Do you need the val != 0 clause? Another thing you could do is leverage go's new max function: return max(0, childValues...)

Copy link
Collaborator

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @aa-joshi, @aerfrei, @arjunmahishi, @asg0451, @rharding6373, and @xinhaoz)


pkg/ccl/changefeedccl/metrics.go line 1208 at r2 (raw file):

				return 0
			}
			return timeutil.Now().UnixNano() - minTs

Is there a reason you chose to do a raw subtraction instead of using the Sub method? From skimming the code, it seems like we usually convert the hlc.Timestamp to a go time and then use Sub.

Copy link
Contributor Author

@aerfrei aerfrei left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @aa-joshi, @andyyang890, @arjunmahishi, @asg0451, @rharding6373, and @xinhaoz)


-- commits line 9 at r2:

Previously, andyyang890 (Andy Yang) wrote…

FYI it's not necessary to put an Epic if you've already linked an issue (linking an issue is preferred per https://cockroachlabs.atlassian.net/wiki/spaces/CRDB/pages/2009039063/Issue+and+Epic+Refs+in+Commits+and+PRs)

I'll change this, thanks for the tip!


pkg/ccl/changefeedccl/metrics.go line 1003 at r2 (raw file):

Previously, andyyang890 (Andy Yang) wrote…

Do you need the val != 0 clause? Another thing you could do is leverage go's new max function: return max(0, childValues...)

Good point on the val check, I'll remove that. I get a compilation error on using max that way, seems like max doesn't support it. https://stackoverflow.com/questions/78778577/a-compilation-error-while-using-builtin-func-max-with-go-1-22-1-invalid-ope


pkg/ccl/changefeedccl/metrics.go line 1208 at r2 (raw file):

Previously, andyyang890 (Andy Yang) wrote…

Is there a reason you chose to do a raw subtraction instead of using the Sub method? From skimming the code, it seems like we usually convert the hlc.Timestamp to a go time and then use Sub.

The reason I did it this way is because I chose to reuse the minTimestampGetter, which returns an int64. If I still wanted to use it, I considered converting back into a timestamp to do the subtraction and then back into nanoseconds like this: "timeutil.Now().Sub(time.Unix(0, minTs)).Nanoseconds()" which seems less readable and I didn't see a strong argument the other way. Thoughts?

Copy link
Collaborator

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @aa-joshi, @aerfrei, @arjunmahishi, @asg0451, @rharding6373, and @xinhaoz)


pkg/ccl/changefeedccl/metrics.go line 1003 at r2 (raw file):

Previously, aerfrei (Aerin Freilich) wrote…

Good point on the val check, I'll remove that. I get a compilation error on using max that way, seems like max doesn't support it. https://stackoverflow.com/questions/78778577/a-compilation-error-while-using-builtin-func-max-with-go-1-22-1-invalid-ope

Ah ok. In that case, maybe you could use slices.Max like the StackOverflow answer says instead?


pkg/ccl/changefeedccl/metrics.go line 1208 at r2 (raw file):

Previously, aerfrei (Aerin Freilich) wrote…

The reason I did it this way is because I chose to reuse the minTimestampGetter, which returns an int64. If I still wanted to use it, I considered converting back into a timestamp to do the subtraction and then back into nanoseconds like this: "timeutil.Now().Sub(time.Unix(0, minTs)).Nanoseconds()" which seems less readable and I didn't see a strong argument the other way. Thoughts?

Ah ok, that makes sense to me.

Copy link
Contributor Author

@aerfrei aerfrei left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @aa-joshi, @andyyang890, @arjunmahishi, @asg0451, @rharding6373, and @xinhaoz)


pkg/ccl/changefeedccl/metrics.go line 1003 at r2 (raw file):

Previously, andyyang890 (Andy Yang) wrote…

Ah ok. In that case, maybe you could use slices.Max like the StackOverflow answer says instead?

Great, done!

@@ -1233,14 +1233,14 @@ func newChangeFrontierProcessor(
return nil, err
}

sliMertics, err := flowCtx.Cfg.JobRegistry.MetricsStruct().Changefeed.(*Metrics).getSLIMetrics(cf.spec.Feed.Opts[changefeedbase.OptMetricsScope])
sliMetrics, err := flowCtx.Cfg.JobRegistry.MetricsStruct().Changefeed.(*Metrics).getSLIMetrics(cf.spec.Feed.Opts[changefeedbase.OptMetricsScope])
Copy link
Contributor

Choose a reason for hiding this comment

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

😂

// for now.
metaChangefeedMaxBehindNanos := metric.Metadata{
Name: "changefeed.max_behind_nanos",
Help: "(Deprecated in favor of checkpoint_progress) The most any changefeed's persisted checkpoint is behind the present",
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe remove the deprecation notice, now that we've improved it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor Author

@aerfrei aerfrei left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @aa-joshi, @andyyang890, @arjunmahishi, @asg0451, @rharding6373, and @xinhaoz)

// for now.
metaChangefeedMaxBehindNanos := metric.Metadata{
Name: "changefeed.max_behind_nanos",
Help: "(Deprecated in favor of checkpoint_progress) The most any changefeed's persisted checkpoint is behind the present",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Currently, changefeed.max_behind_nanos is a measurement of the
lag of the furthest behind changefeed. We'd like to be able to
support scoping/grouping changefeeds. This applies scoping to
that metric similar to the scoping on changefeed.aggregator_progress.

Fixes: cockroachdb#132281

Release note (ops change): the changefeed.max_behind_nanos metric
now supports scoping with metric labels.
@aerfrei
Copy link
Contributor Author

aerfrei commented Dec 19, 2024

bors r=andyyang890,asg0451

@craig craig bot merged commit 9a32312 into cockroachdb:master Dec 19, 2024
22 checks passed
@aerfrei
Copy link
Contributor Author

aerfrei commented Jan 16, 2025

blathers backport 23.2 24.1 24.2 24.3

Copy link

blathers-crl bot commented Jan 16, 2025

Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.


Issue #132281: branch-release-23.2, branch-release-24.1, branch-release-24.2, branch-release-24.3.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Copy link

blathers-crl bot commented Jan 16, 2025

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 0a3420e to blathers/backport-release-23.2-137534: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.2 failed. See errors above.


error creating merge commit from 0a3420e to blathers/backport-release-24.1-137534: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 24.1 failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@aerfrei
Copy link
Contributor Author

aerfrei commented Jan 16, 2025

blathers backport 23.2 24.1 24.2 24.3

Copy link

blathers-crl bot commented Jan 16, 2025

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from 0a3420e to blathers/backport-release-23.2-137534: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.2 failed. See errors above.


error creating merge commit from 0a3420e to blathers/backport-release-24.1-137534: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 24.1 failed. See errors above.


error creating backport branch refs/heads/blathers/backport-release-24.2-137534: POST https://api.github.com/repos/cockroachdb/cockroach/git/refs: 422 Reference already exists []

Backport to branch 24.2 failed. See errors above.


error creating backport branch refs/heads/blathers/backport-release-24.3-137534: POST https://api.github.com/repos/cockroachdb/cockroach/git/refs: 422 Reference already exists []

Backport to branch 24.3 failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

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.

cdc: add checkpoint progress metrics per changefeed
4 participants