mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-09-16 03:24:13 +00:00
[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:
@@ -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()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,19 +1,9 @@
|
|||||||
package dev.sheldan.abstracto.core.repository;
|
package dev.sheldan.abstracto.core.repository;
|
||||||
|
|
||||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.lang.NonNull;
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserRepository extends JpaRepository<AUser, Long> {
|
public interface UserRepository extends JpaRepository<AUser, Long> {
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
Optional<AUser> findById(@NonNull Long aLong);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean existsById(@NonNull Long aLong);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -18,4 +18,5 @@
|
|||||||
<include file="1.2.12/collection.xml" relativeToChangelogFile="true"/>
|
<include file="1.2.12/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.3.0/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.1/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.3.5/collection.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
||||||
@@ -3,6 +3,7 @@ import json
|
|||||||
import liquibase_deploy
|
import liquibase_deploy
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
import templates_deploy
|
import templates_deploy
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
@@ -39,6 +40,12 @@ if not use_folder:
|
|||||||
print("Loading templates")
|
print("Loading templates")
|
||||||
templateLoader = jinja2.FileSystemLoader(searchpath="/python/templates")
|
templateLoader = jinja2.FileSystemLoader(searchpath="/python/templates")
|
||||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||||
|
variable_prefix_pattern = re.compile(r'ABSTRACTO_\w+')
|
||||||
|
variables = {}
|
||||||
|
for key, val in os.environ.items():
|
||||||
|
if variable_prefix_pattern.match(key):
|
||||||
|
variables[key.lower().replace('_', '')] = val
|
||||||
|
|
||||||
template = templateEnv.get_template("liquibase.properties.j2")
|
template = templateEnv.get_template("liquibase.properties.j2")
|
||||||
|
|
||||||
if deploy_liquibase:
|
if deploy_liquibase:
|
||||||
@@ -50,7 +57,8 @@ if not use_folder:
|
|||||||
liquibase_zip.extractall(target_folder)
|
liquibase_zip.extractall(target_folder)
|
||||||
change_log_file = liquibase_artifact['file']
|
change_log_file = liquibase_artifact['file']
|
||||||
liquibase_config_text = template.render(change_log_file=change_log_file, db_host=db_config.host, db_port=db_config.port,
|
liquibase_config_text = template.render(change_log_file=change_log_file, db_host=db_config.host, db_port=db_config.port,
|
||||||
db_database=db_config.database, db_user=db_config.user, db_password=db_config.password, postgres_driver_path=postgres_driver_path)
|
db_database=db_config.database, db_user=db_config.user, db_password=db_config.password,
|
||||||
|
postgres_driver_path=postgres_driver_path, variables=variables)
|
||||||
property_path = target_folder + '/liquibase.properties'
|
property_path = target_folder + '/liquibase.properties'
|
||||||
with open(property_path, 'w') as liquibase_target_properties:
|
with open(property_path, 'w') as liquibase_target_properties:
|
||||||
liquibase_target_properties.write(liquibase_config_text)
|
liquibase_target_properties.write(liquibase_config_text)
|
||||||
|
|||||||
@@ -4,3 +4,6 @@ url: jdbc:postgresql://{{ db_host }}:{{ db_port }}/{{ db_database }}
|
|||||||
username: {{ db_user }}
|
username: {{ db_user }}
|
||||||
password: {{ db_password }}
|
password: {{ db_password }}
|
||||||
classpath: {{ postgres_driver_path }}
|
classpath: {{ postgres_driver_path }}
|
||||||
|
{% for key, value in variables.items() %}
|
||||||
|
parameter.{{ key }}: {{ value }}
|
||||||
|
{% endfor %}
|
||||||
Reference in New Issue
Block a user