Skip to content

Commit

Permalink
providers gui and primefaces 12 update
Browse files Browse the repository at this point in the history
  • Loading branch information
matjaz99 committed Dec 23, 2022
1 parent 0dd3af5 commit c504feb
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 110 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## 2.4.4-SNAPSHOT

* [CHANGE] Removed statistics view (content moved elsewhere)
* [CHANGE] Updated primefaces version 11 to 12
* [CHANGE] Environment variable `ALERTMONITOR_PSYNC_INTERVAL_SEC` is now deprecated, instead `ALERTMONITOR_SYNC_INTERVAL_SEC` should be used.
* [FEATURE] Added environment variable `ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME` to set the name of default data provider.
* [ENHANCEMENT] Http client supports basic authentication for connection to providers

## 2.4.3-SNAPSHOT
Expand All @@ -10,8 +13,8 @@
* [CHANGE] Metric `alertmonitor_webhook_messages_received_total` renamed to `alertmonitor_webhook_requests_received_total`
* [CHANGE] Metric `alertmonitor_journal_messages_total` renamed to `alertmonitor_journal_events_total`
* [FEATURE] Providers view with configuration
* [FEATURE] Added environment variables `ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE` to set configuration file path
and `ALERTMONITOR_HTTP_CLIENT_CONNECT_TIMEOUT_SEC` to configure connection establishment timeout.
* [FEATURE] Added environment variables `ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE` to set providers configuration file path
and `ALERTMONITOR_HTTP_CLIENT_CONNECT_TIMEOUT_SEC` to configure connection establishment timeout

## 2.4.2-SNAPSHOT

Expand Down
50 changes: 32 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,28 @@ to behaviour of the application, while other variables may be used for other pur
configuration or custom environment variable substitution.

> With environment variables, only `.default` data provider (Prometheus) can be configured. Other providers
are configured in `providers.yml` (see Data Providers).
are configured in `providers.yml` (see Data Providers). If providers config file is not found, default data provider
is constructed from environment variables.

A list of supported environment variables:

| EnvVar | Description |
|-----------------------------------------------|--------------------------------------------------------------------------------------------------------|
| ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE | File path to providers.yml configuration file. Default: /opt/alertmonitor/providers.yml |
| ALERTMONITOR_DATA_RETENTION_DAYS | History data in days. Default: 7 |
| ALERTMONITOR_PSYNC_INTERVAL_SEC | Periodic synchronisation interval in seconds. Default: 900 |
| ALERTMONITOR_PROMETHEUS_SERVER | The URL of Prometheus server. Default: http://localhost:9090 |
| ALERTMONITOR_PROMETHEUS_CLIENT_POOL_SIZE | Pool size of http clients for communication with Prometheus API. Default: 1 |
| ALERTMONITOR_HTTP_CLIENT_READ_TIMEOUT_SEC | Timeout of http client requests. Default: 120 |
| ALERTMONITOR_HTTP_CLIENT_CONNECT_TIMEOUT_SEC | Connection timeout of http client. Default: 10 |
| ALERTMONITOR_DATE_FORMAT | Date format for displaying in GUI. Default: yyyy/MM/dd H:mm:ss |
| ALERTMONITOR_KAFKA_ENABLED | Enable or disable publishing to Kafka. This is experimental feature! Default: false |
| ALERTMONITOR_KAFKA_SERVER | Hostname and port for Kafka. Default: hostname:9092 |
| ALERTMONITOR_KAFKA_TOPIC | Name of topic. Default: alertmonitor_notifications |
| ALERTMONITOR_MONGODB_ENABLED | Enable or disable storing data to MongoDB. If disabled, data is stored in memory only. Default: false |
| ALERTMONITOR_MONGODB_CONNECTION_STRING | The connection string for MongoDB (username, password and host). |
| EnvVar | Description |
|--------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE | File path to providers.yml configuration file. Default: /opt/alertmonitor/providers.yml |
| ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME | Name of default data provider. Default: .default |
| ALERTMONITOR_DATA_RETENTION_DAYS | History data in days. Default: 7 |
| ALERTMONITOR_SYNC_INTERVAL_SEC | Periodic synchronisation interval in seconds. Default: 900 |
| ALERTMONITOR_PROMETHEUS_SERVER | The URL of Prometheus server. Default: http://localhost:9090 |
| ALERTMONITOR_PROMETHEUS_CLIENT_POOL_SIZE | Pool size of http clients for communication with Prometheus API. Default: 1 |
| ALERTMONITOR_HTTP_CLIENT_READ_TIMEOUT_SEC | Timeout of http client requests. Default: 120 |
| ALERTMONITOR_HTTP_CLIENT_CONNECT_TIMEOUT_SEC | Connection timeout of http client. Default: 10 |
| ALERTMONITOR_DATE_FORMAT | Date format for displaying in GUI. Default: yyyy/MM/dd H:mm:ss |
| ALERTMONITOR_KAFKA_ENABLED | Enable or disable publishing to Kafka. This is experimental feature! Default: false |
| ALERTMONITOR_KAFKA_SERVER | Hostname and port for Kafka. Default: hostname:9092 |
| ALERTMONITOR_KAFKA_TOPIC | Name of topic. Default: alertmonitor_notifications |
| ALERTMONITOR_MONGODB_ENABLED | Enable or disable storing data to MongoDB. If disabled, data is stored in memory only. Default: false |
| ALERTMONITOR_MONGODB_CONNECTION_STRING | The connection string for MongoDB (username, password and host). |


### Security

Expand Down Expand Up @@ -303,13 +306,24 @@ GET /alertmonitor/metrics

Alertmonitor supports the following metrics in Prometheus format:
- `alertmonitor_build_info`
- `alertmonitor_webhook_messages_received_total`
- `alertmonitor_journal_messages_total`
- `alertmonitor_providers_info`
- `alertmonitor_webhook_requests_received_total`
- `alertmonitor_journal_events_total`
- `alertmonitor_active_alerts_count`
- `alertmonitor_alerts_balance_factor`
- `alertmonitor_last_event_timestamp`
- `alertmonitor_prom_api_duration_seconds`
- `alertmonitor_sync_success`
- `alertmonitor_sync_interval_seconds`
- `alertmonitor_db_inserts_total`
- `alertmonitor_db_queries_total`
- `alertmonitor_db_updates_total`
- `alertmonitor_db_deletes_total`
- `alertmonitor_db_failures_total`
- `alertmonitor_memory_total_bytes`
- `alertmonitor_memory_free_bytes`
- `alertmonitor_memory_max_bytes`
- `alertmonitor_available_processors`


## Log files
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<servlet.version>3.1.0</servlet.version>
<jsf.version>2.2.15</jsf.version>
<!-- <primefaces.version>6.2</primefaces.version>-->
<primefaces.version>11.0.0</primefaces.version>
<!-- <primefaces.version>11.0.0</primefaces.version>-->
<primefaces.version>12.0.0</primefaces.version>
<!-- <prometheus.version>0.6.0</prometheus.version>-->
<prometheus.version>0.12.0</prometheus.version>
<mongodb-driver.version>3.11.3</mongodb-driver.version>
Expand Down
9 changes: 9 additions & 0 deletions providers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ providers:
clientConnectTimeout: 10
clientReadTimeout: 120
syncInterval: 0
- name: dummy
type: prometheus
uri: /alertmonitor/webhook/dummy
params:
server: http://dummy:12345/dummy
clientPoolSize: 10
clientConnectTimeout: 10
clientReadTimeout: 120
syncInterval: 0
4 changes: 2 additions & 2 deletions src/main/java/si/matjazcerkvenik/alertmonitor/data/DAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private DAO() {
}
}
// create default provider if not configured
if (!dataProviders.containsKey(".default")) {
if (!dataProviders.containsKey(AmProps.ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME)) {
ProviderConfig defaultPC = AmProps.generateProviderConfigFromEnvs();
AbstractDataProvider defaultDP = new PrometheusDataProvider();
defaultDP.setProviderConfig(defaultPC);
Expand All @@ -66,7 +66,7 @@ private DAO() {
}
// print data providers
for (AbstractDataProvider adp : dataProviders.values()) {
LogFactory.getLogger().info("Registered ProviderConfig[name=" + adp.getProviderConfig().getName()
LogFactory.getLogger().info("DAO: Registered ProviderConfig[name=" + adp.getProviderConfig().getName()
+ ", type=" + adp.getProviderConfig().getType()
+ ", uri=" + adp.getProviderConfig().getUri() + "]");
AmMetrics.alertmonitor_providers_info.labels(adp.getProviderConfig().getName(), adp.getProviderConfig().getType(), adp.getProviderConfig().getUri()).set(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.yaml.snakeyaml.representer.Representer;
import si.matjazcerkvenik.alertmonitor.providers.PrometheusDataProvider;
import si.matjazcerkvenik.alertmonitor.util.LogFactory;
import si.matjazcerkvenik.alertmonitor.util.MD5;

import java.io.*;
import java.util.List;
Expand All @@ -31,10 +32,9 @@ public static YamlConfig loadProvidersYaml(String path) {
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(YamlConfig.class), representer);
File f = new File(path);
if (!f.exists()) return null;
InputStream inputStream;
try {
inputStream = new FileInputStream(f);
if (!f.exists()) throw new FileNotFoundException();
InputStream inputStream = new FileInputStream(f);
YamlConfig config = yaml.load(inputStream);
LogFactory.getLogger().info("providers config loaded: " + f.getAbsolutePath());
verifyConfigAndSetDefaults(config.getProviders());
Expand All @@ -57,6 +57,7 @@ public static List<ProviderConfig> verifyConfigAndSetDefaults(List<ProviderConfi
for (ProviderConfig pc : configs) {

if (pc.getName() == null) pc.setName("Provider_" + pc.hashCode());
pc.setId(MD5.getChecksum(pc.getName()));
if (pc.getUri() == null) throw new ConfigException("missing uri parameter");
if (pc.getType().equalsIgnoreCase("prometheus")) {
// TODO check params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ public void restartSyncTimer() {
AmMetrics.alertmonitor_sync_interval_seconds.labels(providerConfig.getName()).set(interval);
if (interval == 0) {
LogFactory.getLogger().info("Sync is disabled");
addWarning("SyncDisabled", "Synchronization is disabled");
return;
}

// start resync timer
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/si/matjazcerkvenik/alertmonitor/util/AmProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import si.matjazcerkvenik.alertmonitor.model.config.ProviderConfig;
import si.matjazcerkvenik.alertmonitor.model.config.YamlConfig;
import si.matjazcerkvenik.alertmonitor.model.config.ConfigReader;
import si.matjazcerkvenik.alertmonitor.providers.PrometheusDataProvider;

import java.util.HashMap;
Expand All @@ -37,8 +36,9 @@ public class AmProps {

/** Environment variables */
public static String ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE = "/opt/alertmonitor/providers.yml";
public static String ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME = ".default";
public static int ALERTMONITOR_DATA_RETENTION_DAYS = 7;
public static int ALERTMONITOR_PSYNC_INTERVAL_SEC = 300;
public static int ALERTMONITOR_SYNC_INTERVAL_SEC = 60;
public static String ALERTMONITOR_PROMETHEUS_SERVER = "http://localhost:9090";
public static int ALERTMONITOR_PROMETHEUS_CLIENT_POOL_SIZE = 1;
public static int ALERTMONITOR_HTTP_CLIENT_CONNECT_TIMEOUT_SEC = 10;
Expand All @@ -49,14 +49,17 @@ public class AmProps {
public static String ALERTMONITOR_KAFKA_TOPIC = "alertmonitor_alerts";
public static String ALERTMONITOR_PROMETHEUS_ID_LABELS = "cluster, region, monitor";
public static boolean ALERTMONITOR_MONGODB_ENABLED = false;
public static String ALERTMONITOR_MONGODB_CONNECTION_STRING = "mongodb://admin:mongodbpassword@promvm:27017/test?w=majority&authSource=admin";
public static String ALERTMONITOR_MONGODB_CONNECTION_STRING = "mongodb://admin:mongodbpassword@localhost:27017/test?w=majority&authSource=admin";
public static String ALERTMONITOR_MONGODB_DB_NAME = "alertmonitor";

public static void loadProps() {

// read configuration from environment variables
ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE = System.getenv().getOrDefault("ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE", "/opt/alertmonitor/providers.yml").trim();
ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME = System.getenv().getOrDefault("ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME", ".default").trim();
ALERTMONITOR_DATA_RETENTION_DAYS = Integer.parseInt(System.getenv().getOrDefault("ALERTMONITOR_DATA_RETENTION_DAYS", "30").trim());
ALERTMONITOR_PSYNC_INTERVAL_SEC = Integer.parseInt(System.getenv().getOrDefault("ALERTMONITOR_PSYNC_INTERVAL_SEC", "60").trim());
ALERTMONITOR_SYNC_INTERVAL_SEC = Integer.parseInt(System.getenv().getOrDefault("ALERTMONITOR_PSYNC_INTERVAL_SEC", "60").trim());
ALERTMONITOR_SYNC_INTERVAL_SEC = Integer.parseInt(System.getenv().getOrDefault("ALERTMONITOR_SYNC_INTERVAL_SEC", "60").trim());
if (ALERTMONITOR_PROMETHEUS_SERVER.endsWith("/")) ALERTMONITOR_PROMETHEUS_SERVER = ALERTMONITOR_PROMETHEUS_SERVER.substring(0, ALERTMONITOR_PROMETHEUS_SERVER.length()-1);
ALERTMONITOR_PROMETHEUS_SERVER = System.getenv().getOrDefault("ALERTMONITOR_PROMETHEUS_SERVER", "http://localhost:9090").trim();
if (ALERTMONITOR_PROMETHEUS_SERVER.endsWith("/")) ALERTMONITOR_PROMETHEUS_SERVER = ALERTMONITOR_PROMETHEUS_SERVER.substring(0, ALERTMONITOR_PROMETHEUS_SERVER.length()-1);
Expand All @@ -71,7 +74,7 @@ public static void loadProps() {
ALERTMONITOR_PROMETHEUS_ID_LABELS = System.getenv().getOrDefault("ALERTMONITOR_PROMETHEUS_ID_LABELS", "cluster, region, monitor").trim();
ALERTMONITOR_MONGODB_ENABLED = Boolean.parseBoolean(System.getenv().getOrDefault("ALERTMONITOR_MONGODB_ENABLED", "false").trim());
// AmProps.ALERTMONITOR_MONGODB_CONNECTION_STRING = System.getenv().getOrDefault("ALERTMONITOR_MONGODB_CONNECTION_STRING", "mongodb://admin:mongodbpassword@promvm:27017/test?w=majority&authSource=admin").trim();
ALERTMONITOR_MONGODB_CONNECTION_STRING = System.getenv().getOrDefault("ALERTMONITOR_MONGODB_CONNECTION_STRING", "mongodb://admin:mongodbpassword@promvm:27017/?authSource=admin").trim();
ALERTMONITOR_MONGODB_CONNECTION_STRING = System.getenv().getOrDefault("ALERTMONITOR_MONGODB_CONNECTION_STRING", "mongodb://admin:mongodbpassword@localhost:27017/?authSource=admin").trim();

// set development environment, override default configuration
if (DEV_ENV) {
Expand All @@ -86,7 +89,8 @@ public static void loadProps() {

public static ProviderConfig generateProviderConfigFromEnvs() {
ProviderConfig config = new ProviderConfig();
config.setName(".default");
config.setName(ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME);
config.setId(MD5.getChecksum(ALERTMONITOR_DATAPROVIDERS_DEFAULT_PROVIDER_NAME));
config.setType("prometheus");
config.setUri(ALERTMONITOR_DEFAULT_WEBHOOK_URI);

Expand All @@ -95,7 +99,7 @@ public static ProviderConfig generateProviderConfigFromEnvs() {
params.put(PrometheusDataProvider.DP_PARAM_KEY_CLIENT_POOL_SIZE, ALERTMONITOR_PROMETHEUS_CLIENT_POOL_SIZE);
params.put(PrometheusDataProvider.DP_PARAM_KEY_CLIENT_CONNECT_TIMEOUT_SEC, ALERTMONITOR_HTTP_CLIENT_CONNECT_TIMEOUT_SEC);
params.put(PrometheusDataProvider.DP_PARAM_KEY_CLIENT_READ_TIMEOUT_SEC, ALERTMONITOR_HTTP_CLIENT_READ_TIMEOUT_SEC);
params.put(PrometheusDataProvider.DP_PARAM_KEY_SYNC_INTERVAL_SEC, ALERTMONITOR_PSYNC_INTERVAL_SEC);
params.put(PrometheusDataProvider.DP_PARAM_KEY_SYNC_INTERVAL_SEC, ALERTMONITOR_SYNC_INTERVAL_SEC);

config.setParams(params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {

// load yaml config file
AmProps.yamlConfig = ConfigReader.loadProvidersYaml(AmProps.ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE);
System.out.println(AmProps.yamlConfig.toString());

// initialize DAO
DAO.getInstance();
Expand Down
Loading

0 comments on commit c504feb

Please sign in to comment.