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

Record metrics when INIT revision or an old revision is used #874

Merged
merged 10 commits into from
Sep 4, 2023

Conversation

minwoox
Copy link
Member

@minwoox minwoox commented Aug 28, 2023

Motivation:
Before we apply #681 that removes old commits, it would be nice if we could find any usages that access data with the INIT Revision or revisions that are more than 5000 (default minimum number of commit retentions) commits ahead from the head.

Modifications:

  • Add a counter that is increased when INIT Revision or revisions that are more than 5000 ahead from the head are used.

Result:

  • Track the number of usages.
  • This commit will be reverted after we find the usage and fix it.

Motivation:
Before we apply line#681 that removes old commits,
it would be nice if we can find any usages that access data with the INIT Revision or
revisions that are more than 5000 (default minimum number of commit retentions) commits ahead from the head.

Modifications:
- Add a counter that is incresed when INIT Revision or revisions that are more than 5000 ahead from the head are used.

Result:
- Track the number of usages.
- This commit will be reverted after we find the usage and fix it.
ServiceRequestContext ctx, String projectName, String repoName,
Revision normalized, Revision head) {
if (normalized.major() == 1 || head.major() - normalized.major() >= 5000) {
ctx.log().whenComplete().thenAccept(log -> {
Copy link
Contributor

@jrhee17 jrhee17 Aug 28, 2023

Choose a reason for hiding this comment

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

Question) Do we want to differentiate between cases using 1 vs. >5000?
Imagining that the counter goes up, I wonder if we want to know which case needs handling.

Nevermind, I realized you added the revision as a tag

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Left some minor comments, but basically looks good 👍

Tag.of("repo", repoName),
Tag.of("service", firstNonNull(log.serviceName(), "none")),
Tag.of("method", log.name()),
Tag.of("normalized", Integer.toString(normalized.major())),
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of adding a tag which can increase cardinality, what do you think of just adding a distribution?

i.e. If there is a repo with head version 1M, this is the possible cardinality worse case.

ctx.meterRegistry().summary("").record(head.major() - normalized.major());
ctx.meterRegistry().counter("", "init.major", String.valueOf(normalized.major() == 1)).increment();

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added the metric with the assumption that this will be short-lived and there will not be many requests that are caught by the condition.
However, there's no reason not to decrease the cardinality so let me use the distribution. Thanks!

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 added the metric with the assumption that this will be short-lived and there will not be many requests that are caught by the condition.

I agree, but I also thought this code will also need to go to production env. to confirm our hypothesis 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

That is correct. 🤣

@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Patch coverage: 83.90% and project coverage change: +0.04% 🎉

Comparison is base (6b10542) 65.69% compared to head (dce6327) 65.73%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #874      +/-   ##
============================================
+ Coverage     65.69%   65.73%   +0.04%     
- Complexity     3350     3351       +1     
============================================
  Files           358      358              
  Lines         13893    13954      +61     
  Branches       1496     1502       +6     
============================================
+ Hits           9127     9173      +46     
- Misses         3914     3924      +10     
- Partials        852      857       +5     
Files Changed Coverage Δ
...dogma/server/internal/api/RepositoryServiceV1.java 73.43% <70.37%> (-2.24%) ⬇️
...erver/internal/mirror/DefaultMirroringService.java 67.67% <71.42%> (-0.04%) ⬇️
...raldogma/server/internal/api/ContentServiceV1.java 86.98% <100.00%> (+0.41%) ⬆️
...raldogma/server/internal/mirror/MirroringTask.java 100.00% <100.00%> (ø)
...erver/internal/thrift/CentralDogmaServiceImpl.java 76.59% <100.00%> (+1.94%) ⬆️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍 Thanks @minwoox ! 🙇 👍 🚀

@@ -22,5 +22,7 @@ if (tasks.findByName('trimShadedJar')) {
keep "class com.linecorp.centraldogma.internal.shaded.caffeine.** { *; }"
// Prevent ProGuard from removing all enum values from Option because otherwise it becomes a non-enum class.
keep "class com.linecorp.centraldogma.internal.shaded.jsonpath.Option { *; }"

dontnote
Copy link
Member Author

Choose a reason for hiding this comment

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

This reduces the verbosity of ProGuardTask when running in parallel.
The original comment: https://github.com/line/armeria/pull/2172/files#r332367951

Copy link
Member

Choose a reason for hiding this comment

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

Please add a line comment about it.

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

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

New changes still look good 👍

@@ -22,5 +22,7 @@ if (tasks.findByName('trimShadedJar')) {
keep "class com.linecorp.centraldogma.internal.shaded.caffeine.** { *; }"
// Prevent ProGuard from removing all enum values from Option because otherwise it becomes a non-enum class.
keep "class com.linecorp.centraldogma.internal.shaded.jsonpath.Option { *; }"

dontnote
Copy link
Member

Choose a reason for hiding this comment

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

Please add a line comment about it.

if (normalized.major() == 1) {
ctx.log().whenComplete().thenAccept(
log -> ctx.meterRegistry()
.counter("init.revisions", generateTags(projectName, repoName, log).build())
Copy link
Member

Choose a reason for hiding this comment

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

revisions.init?

if (head.major() - normalized.major() >= 5000) {
ctx.log().whenComplete().thenAccept(
log -> ctx.meterRegistry()
.summary("old.revisions",
Copy link
Member

Choose a reason for hiding this comment

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

revisions.old?

// Trigger old revision recording
jsonNodeWatchRequest.start(Revision.INIT).join();
content = dogma.httpClient().get("/monitor/metrics").aggregate().join().contentUtf8();
assertThat(content).contains("init_revisions");
Copy link
Member

Choose a reason for hiding this comment

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

Can we also add a similar test for old_revisions? Should check if the meters with init=true and init=false both exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

All addressed. PTAL. 😉

Copy link
Contributor

@ikhoon ikhoon left a comment

Choose a reason for hiding this comment

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

Thanks, @minwoox

}

public static void increaseCounterIfOldRevisionUsed(
ServiceRequestContext ctx, String projectName, String repoName,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It may be simpler.

Suggested change
ServiceRequestContext ctx, String projectName, String repoName,
ServiceRequestContext ctx, Repository repository,

ServiceRequestContext ctx, String projectName, String repoName,
Revision normalized, Revision head) {
if (normalized.major() == 1) {
ctx.log().whenComplete().thenAccept(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ctx.log.whenRequestComplete() could be used instead since RequestLogProperty.NAME is a request property. But I'm okay with the current implementation for simplicity.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! All addressed. 😉

@minwoox
Copy link
Member Author

minwoox commented Sep 4, 2023

Thanks for reviewing. 😉

@minwoox minwoox merged commit c0fdd1a into line:main Sep 4, 2023
10 of 11 checks passed
@minwoox minwoox deleted the old_revision branch September 4, 2023 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants