[AB-xxx] adding JDA metrics for all events

adding support to template environment variables in liquibase configuration
removing not needed column from component payload
This commit is contained in:
Sheldan
2021-07-25 15:17:27 +02:00
parent 3f67593ef4
commit ee7f9180dc
8 changed files with 91 additions and 12 deletions

View File

@@ -0,0 +1,43 @@
package dev.sheldan.abstracto.core.metric;
import dev.sheldan.abstracto.core.metric.service.CounterMetric;
import dev.sheldan.abstracto.core.metric.service.MetricService;
import dev.sheldan.abstracto.core.metric.service.MetricTag;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.events.GenericEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.HashMap;
@Component
@Slf4j
public class JDAMetrics extends ListenerAdapter {
@Autowired
private MetricService metricService;
public static final String JDA_EVENT_METRIC = "jda.event";
public static final String EVENT_CLASS = "event.class";
private final HashMap<Class, CounterMetric> coveredEvents = new HashMap<>();
@Override
public void onGenericEvent(@NotNull GenericEvent event) {
if(!coveredEvents.containsKey(event.getClass())) {
String eventName = event.getClass().getSimpleName();
CounterMetric metric =
CounterMetric
.builder()
.tagList(Arrays.asList(MetricTag.getTag(EVENT_CLASS, eventName)))
.name(JDA_EVENT_METRIC)
.build();
log.info("Registering new metric for event {}. There are now {} metrics.", eventName, coveredEvents.size());
metricService.registerCounter(metric, "Events of type " + eventName);
coveredEvents.put(event.getClass(), metric);
}
metricService.incrementCounter(coveredEvents.get(event.getClass()));
}
}

View File

@@ -1,19 +1,9 @@
package dev.sheldan.abstracto.core.repository;
import dev.sheldan.abstracto.core.models.database.AUser;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Repository;
import java.util.Optional;
@Repository
public interface UserRepository extends JpaRepository<AUser, Long> {
@NotNull
@Override
Optional<AUser> findById(@NonNull Long aLong);
@Override
boolean existsById(@NonNull Long aLong);
}

View File

@@ -0,0 +1,10 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd">
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -0,0 +1,14 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
<changeSet author="Sheldan" id="component_payload-dropType">
<dropColumn tableName="component_payload">
<column name="payload_type" type="VARCHAR(100)" />
</dropColumn>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,10 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
<include file="component_payload.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>

View File

@@ -18,4 +18,5 @@
<include file="1.2.12/collection.xml" relativeToChangelogFile="true"/>
<include file="1.3.0/collection.xml" relativeToChangelogFile="true"/>
<include file="1.3.1/collection.xml" relativeToChangelogFile="true"/>
<include file="1.3.5/collection.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>