Skip to content

Commit

Permalink
Merge pull request #606 from FgForrest/18-web-api-metrics
Browse files Browse the repository at this point in the history
feat(#18): count REST endpoints metric
  • Loading branch information
lukashornych authored Jun 17, 2024
2 parents aa3740d + 841cf72 commit 2b31ac4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ private void registerSystemApi() {
systemBuildStatistics = SystemBuildStatistics.createNew(
instanceBuildDuration,
schemaBuildDuration,
countOpenApiSchemaLines(api.openApi())
countOpenApiSchemaLines(api.openApi()),
api.openApi().getPaths().size()
);
}

Expand Down Expand Up @@ -165,7 +166,8 @@ public void registerCatalog(@Nonnull String catalogName) {
final CatalogBuildStatistics buildStatistics = CatalogBuildStatistics.createNew(
instanceBuildDuration,
schemaBuildDuration,
countOpenApiSchemaLines(api.openApi())
countOpenApiSchemaLines(api.openApi()),
api.openApi().getPaths().size()
);
catalogBuildStatistics.put(catalogName, buildStatistics);
} catch (EvitaInternalError ex) {
Expand Down Expand Up @@ -222,7 +224,8 @@ public void refreshCatalog(@Nonnull String catalogName) {
buildStatistics.refresh(
instanceBuildDuration,
schemaBuildDuration,
countOpenApiSchemaLines(newApi.openApi())
countOpenApiSchemaLines(newApi.openApi()),
newApi.openApi().getPaths().size()
);
}

Expand All @@ -241,7 +244,8 @@ public void emitObservabilityEvents() {
BuildType.NEW,
systemBuildStatistics.instanceBuildDuration(),
systemBuildStatistics.schemaBuildDuration(),
systemBuildStatistics.schemaDslLines()
systemBuildStatistics.schemaDslLines(),
systemBuildStatistics.registeredEndpoints()
).commit();

systemBuildStatistics.markAsReported();
Expand All @@ -267,7 +271,8 @@ public void emitObservabilityEvents(@Nonnull String catalogName) {
buildStatistics.buildCount().get() == 1 ? BuildType.NEW : BuildType.REFRESH,
buildStatistics.instanceBuildDuration().get(),
buildStatistics.schemaBuildDuration().get(),
buildStatistics.schemaDslLines().get()
buildStatistics.schemaDslLines().get(),
buildStatistics.registeredEndpoints().get()
).commit();
}

Expand All @@ -287,16 +292,19 @@ private long countOpenApiSchemaLines(@Nonnull OpenAPI schema) {
private record SystemBuildStatistics(@Nonnull AtomicBoolean reported,
long instanceBuildDuration,
long schemaBuildDuration,
long schemaDslLines) {
long schemaDslLines,
long registeredEndpoints) {

public static SystemBuildStatistics createNew(long instanceBuildDuration,
long schemaBuildDuration,
long schemaDslLines) {
long schemaDslLines,
long registeredEndpoints) {
return new SystemBuildStatistics(
new AtomicBoolean(false),
instanceBuildDuration,
schemaBuildDuration,
schemaDslLines
schemaDslLines,
registeredEndpoints
);
}

Expand All @@ -308,26 +316,31 @@ public void markAsReported() {
private record CatalogBuildStatistics(@Nonnull AtomicInteger buildCount,
@Nonnull AtomicLong instanceBuildDuration,
@Nonnull AtomicLong schemaBuildDuration,
@Nonnull AtomicLong schemaDslLines) {
@Nonnull AtomicLong schemaDslLines,
@Nonnull AtomicLong registeredEndpoints) {

public static CatalogBuildStatistics createNew(long instanceBuildDuration,
long schemaBuildDuration,
long schemaDslLines) {
long schemaDslLines,
long registeredEndpoints) {
return new CatalogBuildStatistics(
new AtomicInteger(1),
new AtomicLong(instanceBuildDuration),
new AtomicLong(schemaBuildDuration),
new AtomicLong(schemaDslLines)
new AtomicLong(schemaDslLines),
new AtomicLong(registeredEndpoints)
);
}

public void refresh(long instanceBuildDuration,
long schemaBuildDuration,
long schemaDslLines) {
long schemaDslLines,
long registeredEndpoints) {
this.buildCount.incrementAndGet();
this.instanceBuildDuration.set(instanceBuildDuration);
this.schemaBuildDuration.set(schemaBuildDuration);
this.schemaDslLines.set(schemaDslLines);
this.registeredEndpoints.set(registeredEndpoints);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,24 @@ public class BuiltEvent extends AbstractRestInstanceEvent {
@ExportMetric(metricType = MetricType.GAUGE)
private long schemaDslLines;

@Label("Number of registered endpoints in built OpenAPI schema")
@ExportMetric(metricType = MetricType.GAUGE)
private long registeredEndpoints;

public BuiltEvent(@Nonnull RestInstanceType instanceType,
@Nonnull BuildType buildType,
long instanceBuildDuration,
long schemaBuildDuration,
long schemaDslLines) {
long schemaDslLines,
long registeredEndpoints) {
this(
null,
instanceType,
buildType,
instanceBuildDuration,
schemaBuildDuration,
schemaDslLines
schemaDslLines,
registeredEndpoints
);
}

Expand All @@ -101,13 +107,15 @@ public BuiltEvent(@Nonnull String catalogName,
@Nonnull BuildType buildType,
long instanceBuildDuration,
long schemaBuildDuration,
long schemaDslLines) {
long schemaDslLines,
long registeredEndpoints) {
this.catalogName = catalogName;
this.instanceType = instanceType.name();
this.buildType = buildType.name();
this.instanceBuildDuration = instanceBuildDuration;
this.schemaBuildDuration = schemaBuildDuration;
this.schemaDslLines = schemaDslLines;
this.registeredEndpoints = registeredEndpoints;
}

/**
Expand Down

0 comments on commit 2b31ac4

Please sign in to comment.