Skip to content

Commit

Permalink
Add methods to delete query metrics (#499)
Browse files Browse the repository at this point in the history
  • Loading branch information
yash0024 authored Jan 9, 2025
1 parent 27bd8bc commit ca98365
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public ArtifactsPurgeServiceImpl(ManageProjectsService projects, VersionsReconci
this.versionsMismatchService = versionsMismatchService;
}

protected QueryMetricsService getQueryMetricsService()
{
return metrics;
}

private Set<ArtifactType> getSupportedArtifactTypes()
{
Expand Down Expand Up @@ -134,6 +138,7 @@ public void evict(String groupId, String artifactId, String versionId)
projectData.setEvicted(true);
LOGGER.info(String.format("%s-%s-%s evicted", groupId, artifactId, versionId));
PrometheusMetricsFactory.getInstance().incrementCount(VERSION_PURGE_COUNTER);
metrics.delete(groupId, artifactId, versionId);
return projects.createOrUpdate(projectData);
},decorateSpanWithVersionInfo(groupId, artifactId, versionId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ public interface QueryMetricsService

List<VersionQueryMetric> findSnapshotVersionMetricsBefore(Date date);

List<VersionQueryMetric> getStaleMetrics(int ttlForVersionsInDays, int ttlForSnapshotsInDays);

void consolidateMetrics();

void persist(QueryMetricsRegistry registry);

void delete(String groupId, String artifactId, String versionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ public interface QueryMetrics

List<VersionQueryMetric> findMetricsBefore(Date date);

long delete(String groupId, String artifactId, String versionId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package org.finos.legend.depot.services.metrics.query;

import com.google.inject.name.Named;
import org.finos.legend.depot.domain.version.VersionValidator;
import org.finos.legend.depot.services.api.metrics.query.QueryMetricsRegistry;
import org.finos.legend.depot.services.api.metrics.query.QueryMetricsService;
Expand All @@ -24,6 +23,7 @@
import org.slf4j.Logger;

import javax.inject.Inject;
import java.time.Duration;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -93,6 +93,26 @@ public void persist(QueryMetricsRegistry registry)

}

public void delete(String groupId, String artifactId, String versionId)
{
metricsStore.delete(groupId, artifactId, versionId);
}

private boolean checkDateBeforeNumDays(Date date, int numDays)
{
return date.before(new Date(System.currentTimeMillis() - Duration.ofDays(numDays).toMillis()));
}

public List<VersionQueryMetric> getStaleMetrics(int ttlForVersionsInDays, int ttlForSnapshotsInDays)
{
return metricsStore.getAll().stream()
.filter(metric ->
(VersionValidator.isSnapshotVersion(metric.getVersionId()) && checkDateBeforeNumDays(metric.getLastQueryTime(), ttlForSnapshotsInDays))
|| checkDateBeforeNumDays(metric.getLastQueryTime(), ttlForVersionsInDays)
)
.collect(Collectors.toList());
}

public void consolidateMetrics()
{
LOGGER.info("Started consolidating metrics for all project versions");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ public List<VersionQueryMetric> findMetricsBefore(Date date)
return find(lte("lastQueryTime", date.getTime()));
}

@Override
public long delete(String groupId, String artifactId, String versionId)
{
delete(getKeyFilter(groupId, artifactId, versionId));
return 1;
}

@Override
protected Bson getKeyFilter(VersionQueryMetric data)
{
Expand Down

0 comments on commit ca98365

Please sign in to comment.