-
Notifications
You must be signed in to change notification settings - Fork 121
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
Changes from 1 commit
4234a49
a302f38
37e6a85
82fa47c
2b5fd93
a89d781
24ef8be
f295224
d1d36a2
dce6327
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.linecorp.centraldogma.server.internal.api; | ||
|
||
import static com.google.common.base.MoreObjects.firstNonNull; | ||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
import static com.linecorp.centraldogma.server.internal.api.HttpApiUtil.checkUnremoveArgument; | ||
import static com.linecorp.centraldogma.server.internal.api.HttpApiUtil.returnOrThrow; | ||
|
@@ -28,9 +29,11 @@ | |
import javax.annotation.Nullable; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
|
||
import com.linecorp.armeria.common.HttpStatus; | ||
import com.linecorp.armeria.common.logging.RequestLog; | ||
import com.linecorp.armeria.server.ServiceRequestContext; | ||
import com.linecorp.armeria.server.annotation.Consumes; | ||
import com.linecorp.armeria.server.annotation.Delete; | ||
|
@@ -58,6 +61,8 @@ | |
import com.linecorp.centraldogma.server.storage.project.ProjectManager; | ||
import com.linecorp.centraldogma.server.storage.repository.Repository; | ||
|
||
import io.micrometer.core.instrument.Tag; | ||
|
||
/** | ||
* Annotated service object for managing repositories. | ||
*/ | ||
|
@@ -186,8 +191,41 @@ public CompletableFuture<RepositoryDto> patchRepository(@Param String repoName, | |
*/ | ||
@Get("/projects/{projectName}/repos/{repoName}/revision/{revision}") | ||
@RequiresReadPermission | ||
public Map<String, Integer> normalizeRevision(Repository repository, @Param String revision) { | ||
public Map<String, Integer> normalizeRevision(ServiceRequestContext ctx, | ||
Repository repository, @Param String revision) { | ||
final Revision normalizedRevision = repository.normalizeNow(new Revision(revision)); | ||
final Revision head = repository.normalizeNow(Revision.HEAD); | ||
increaseCounterIfOldRevisionUsed(ctx, repository.parent().name(), repository.name(), | ||
normalizedRevision, head); | ||
return ImmutableMap.of("revision", normalizedRevision.major()); | ||
} | ||
|
||
static void increaseCounterIfOldRevisionUsed(ServiceRequestContext ctx, Repository repository, | ||
Revision revision) { | ||
final Revision normalized = repository.normalizeNow(revision); | ||
final Revision head = repository.normalizeNow(Revision.HEAD); | ||
increaseCounterIfOldRevisionUsed(ctx, repository.parent().name(), repository.name(), normalized, head); | ||
} | ||
|
||
public static void increaseCounterIfOldRevisionUsed( | ||
ServiceRequestContext ctx, String projectName, String repoName, | ||
Revision normalized, Revision head) { | ||
if (normalized.major() == 1 || head.major() - normalized.major() >= 5000) { | ||
ctx.log().whenComplete().thenAccept(log -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Nevermind, I realized you added the revision as a tag |
||
ctx.meterRegistry().counter("dogma.old.revision", | ||
generateTags(projectName, repoName, log, normalized, head)) | ||
.increment(); | ||
}); | ||
} | ||
} | ||
|
||
private static List<Tag> generateTags(String projectName, String repoName, | ||
RequestLog log, Revision normalized, Revision head) { | ||
return ImmutableList.of(Tag.of("project", projectName), | ||
Tag.of("repo", repoName), | ||
Tag.of("service", firstNonNull(log.serviceName(), "none")), | ||
Tag.of("method", log.name()), | ||
Tag.of("normalized", Integer.toString(normalized.major())), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree, but I also thought this code will also need to go to production env. to confirm our hypothesis 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is correct. 🤣 |
||
Tag.of("head", Integer.toString(head.major()))); | ||
} | ||
} |
minwoox marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
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.