Skip to content

Commit

Permalink
Added counters
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Sep 24, 2022
1 parent 21a5a15 commit 4377243
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/main/java/jasper/component/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.micrometer.core.annotation.Counted;
import jasper.config.ApplicationProperties;
import jasper.domain.Ext;
import jasper.domain.Plugin;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class Backup {

@Async
@Transactional(readOnly = true)
@Counted(value = "jasper.backup", extraTags = {"method", "create"})
public void createBackup(String id, BackupOptionsDto options) throws IOException {
var start = Instant.now();
log.info("Creating Backup");
Expand Down Expand Up @@ -133,6 +135,7 @@ private void backupRepo(StreamMixin<?> repo, Path path, boolean evict) throws IO
Files.write(path, "]\n".getBytes(), StandardOpenOption.APPEND);
}

@Counted(value = "jasper.backup", extraTags = {"method", "download"})
public byte[] get(String id) {
try {
return Files.readAllBytes(path(id));
Expand All @@ -157,6 +160,7 @@ public List<String> listBackups() {
}

@Async
@Counted(value = "jasper.backup", extraTags = {"method", "restore"})
public void restore(String id, BackupOptionsDto options) {
var start = Instant.now();
log.info("Restoring Backup");
Expand Down Expand Up @@ -193,6 +197,7 @@ private <T> void restoreRepo(JpaRepository<T, ?> repo, Path path, Class<T> type)
}
}

@Deprecated
private void upgradeFeed(Path path) {
try {
new JsonArrayStreamDataSupplier<>(Files.newInputStream(path), OldFeed.class, objectMapper)
Expand Down Expand Up @@ -222,12 +227,14 @@ private void upgradeFeed(Path path) {
}
}

@Counted(value = "jasper.backup", extraTags = {"method", "upload"})
public void store(String id, byte[] zipFile) throws IOException {
var path = path(id);
Files.createDirectories(path.getParent());
Files.write(path, zipFile, StandardOpenOption.CREATE);
}

@Counted(value = "jasper.backup", extraTags = {"method", "delete"})
public void delete(String id) throws IOException {
Files.delete(path(id));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/jasper/component/Ingest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void backfillMetadata() {
}
}

@Counted("jasper.ref.create")
@Counted(value = "jasper.ref", extraTags = {"method", "create"})
public void ingest(Ref ref) {
if (refRepository.existsByUrlAndOrigin(ref.getUrl(), ref.getOrigin())) throw new AlreadyExistsException();
if (refRepository.existsByAlternateUrlAndOrigin(ref.getUrl(), ref.getOrigin())) throw new AlreadyExistsException();
Expand All @@ -51,7 +51,7 @@ public void ingest(Ref ref) {
ensureUniqueModified(ref);
}

@Counted("jasper.ref.update")
@Counted(value = "jasper.ref", extraTags = {"method", "update"})
public void update(Ref ref) {
var maybeExisting = refRepository.findOneByUrlAndOrigin(ref.getUrl(), ref.getOrigin());
if (maybeExisting.isEmpty()) throw new NotFoundException("Ref");
Expand All @@ -78,7 +78,7 @@ private void ensureUniqueModified(Ref ref) {
}
}

@Counted("jasper.ref.delete")
@Counted(value = "jasper.ref", extraTags = {"method", "delete"})
public void delete(String url, String origin) {
var maybeExisting = refRepository.findOneByUrlAndOrigin(url, origin);
if (maybeExisting.isEmpty()) return;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jasper/component/Meta.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jasper.component;

import io.micrometer.core.annotation.Counted;
import jasper.domain.Metadata;
import jasper.domain.Ref;
import jasper.repository.PluginRepository;
Expand Down Expand Up @@ -28,6 +29,7 @@ public class Meta {
@Autowired
PluginRepository pluginRepository;

@Counted("jasper.meta.update")
public void update(Ref ref, Ref existing) {
// TODO: make async
if (ref != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/jasper/component/Replicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.micrometer.core.annotation.Counted;
import jasper.client.JasperClient;
import jasper.config.ApplicationProperties;
import jasper.domain.Ref;
Expand Down Expand Up @@ -50,7 +51,7 @@ public class Replicator {
@Autowired
ObjectMapper objectMapper;


@Counted("jasper.replicate")
public void replicate(Ref origin) {
var config = objectMapper.convertValue(origin.getPlugins().get("+plugin/origin"), Origin.class);
config.setLastScrape(Instant.now());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jasper/component/RssParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.rometools.rome.io.FeedException;
import com.rometools.rome.io.SyndFeedInput;
import com.rometools.rome.io.XmlReader;
import io.micrometer.core.annotation.Counted;
import jasper.domain.Ref;
import jasper.errors.AlreadyExistsException;
import jasper.plugin.Feed;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class RssParser {
@Autowired
ObjectMapper objectMapper;

@Counted("jasper.feed")
public void scrape(Ref feed) throws IOException, FeedException {
var config = objectMapper.convertValue(feed.getPlugins().get("+plugin/feed"), Feed.class);
var lastScrape = config.getLastScrape();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jasper/component/WebScraper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package jasper.component;

import io.micrometer.core.annotation.Counted;
import jasper.domain.Ref;
import org.jsoup.Jsoup;
import org.slf4j.Logger;
Expand All @@ -14,6 +15,7 @@
public class WebScraper {
private static final Logger logger = LoggerFactory.getLogger(WebScraper.class);

@Counted(value = "jasper.webscrape")
public Ref scrape(String url) throws IOException {
var doc = Jsoup.connect(url).get();
var result = new Ref();
Expand Down

0 comments on commit 4377243

Please sign in to comment.