Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions compose/demo-distributed/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ services:
- "8080:8080"
environment:
WOMBAT_MODE: aggregator
QUARKUS_DATASOURCE_JDBC_URL: "jdbc:sqlite:/var/data/local.db"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be closer to reality to have a postgres setup for the aggregator

PERSISTENCE_BACKEND_MODE: sqlite
PERSISTENCE_BACKEND_SQLITE_JDBC_URL: "jdbc:sqlite:/var/data/local.db"
# Fold sampling rows every 5 minutes instead of every hour, so pushed activity reaches the UI within minutes
COMPACTION_CRON: "0 1/5 * * * ?"
COMPACTION_WINDOW: 5m
COMPACTION_DELAY: 30s
CONNECTOR_BOAVIZTA_URI: "http://boavizta:5000/v1/"
CONNECTOR_ECOLOGITS_URI: "http://ecologits:80/"
PERSISTENCE_COMPACTION_CRON: "0 1/5 * * * ?"
PERSISTENCE_COMPACTION_WINDOW: 5m
PERSISTENCE_COMPACTION_DELAY: 30s
WOMBAT_CONNECTOR_BOAVIZTA_URI: "http://boavizta:5000/v1/"
WOMBAT_CONNECTOR_ECOLOGITS_URI: "http://ecologits:80/"
# Secret of the Anthropic asset of aggregator/monitored-environments.yaml, which is evaluated here
ANTHROPIC_ADMIN_KEY: "${ANTHROPIC_ADMIN_KEY:-}"
volumes:
Expand Down
63 changes: 30 additions & 33 deletions compose/demo-standalone/application.yaml.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
quarkus:
datasource:
jdbc:
url: "jdbc:sqlite:/var/data/local.db"
persistence:
backend:
mode: sqlite
#mode: postgresql
sqlite:
jdbc-url: "jdbc:sqlite:/var/data/local.db"
# # Local S3 Backup setup (e.g. SeaweedFS service)
# backup:
# enabled: false
# cron: "0 0 * * * ?" # hourly
# s3:
# key-prefix: sqlite/
# endpoint: http://localhost:8333
# bucket: wombat-bucket
# region: us-east-1
# access-key: admin
# secret-key: secret
# # Alternative PostgreSQL backend:
# postgresql:
# jdbc-url: "jdbc:postgresql://localhost:5432/wombat"
# username: wombat
# password: wombat

# Alternative PostgreSQL Datasource for dev:
# quarkus:
# datasource:
# db-kind: postgresql
# username: wombat
# password: wombat
# jdbc:
# url: "jdbc:postgresql://localhost:5432/wombat"

connector:
boavizta:
uri: "http://boavizta:5000/v1/"
ecologits:
uri: "http://ecologits:80/"

# Local S3 Backup setup (e.g. SeaweedFS service)
# backup:
# enabled: false
# cron: "0 0 * * * ?" # hourly
# s3:
# key-prefix: sqlite/
# endpoint: http://localhost:8333
# bucket: wombat-bucket
# region: us-east-1
# access-key: admin
# secret-key: secret

# Optional Secret resolution directory:
# wombat:
wombat:
# # Optional Secret resolution directory:
# secret:
# directory:
# path: /secrets

connector:
boavizta:
uri: "http://boavizta:5000/v1/"
ecologits:
uri: "http://ecologits:80/"
10 changes: 5 additions & 5 deletions doc/compaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Sourced metrics are written as raw samples every 5 minutes, then periodically fo
The dashboard and the HTTP API only read compacted rows, so the compaction window is the delay before fresh activity
becomes visible.

| Property | Default | Description |
|----------------------|---------------|--------------------------------------------------------------------------------------------------|
| `compaction.cron` | `0 1 * * * ?` | When compaction runs. Only closed windows are folded, so running it more often than they close is wasted. |
| `compaction.window` | `1h` | Width of the compacted windows. Must be a multiple of the 5-minute sampling step and divide an hour (`5m`, `10m`, `15m`, `20m`, `30m`, `1h`); the app refuses to start otherwise. |
| `compaction.delay` | `1m` | How long after its end a window is left alone, so the last raw samples land in it before it is folded. |
| Property | Default | Description |
|---------------------------------|---------------|--------------------------------------------------------------------------------------------------|
| `persistence.compaction.cron` | `0 1 * * * ?` | When compaction runs. Only closed windows are folded, so running it more often than they close is wasted. |
| `persistence.compaction.window` | `1h` | Width of the compacted windows. Must be a multiple of the 5-minute sampling step and divide an hour (`5m`, `10m`, `15m`, `20m`, `30m`, `1h`); the app refuses to start otherwise. |
| `persistence.compaction.delay` | `1m` | How long after its end a window is left alone, so the last raw samples land in it before it is folded. |

> [!IMPORTANT]
> Keeping the default settings in production is highly recommended. A shorter window is meant for development, where
Expand Down
4 changes: 1 addition & 3 deletions doc/distributed.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ a minute. A declaration that fails is logged, and the next one tries again. Remo
removes it from the aggregator at the worker's next startup.

No metric is written to the worker's database, so a worker always runs on an in-memory SQLite database, whatever its
`quarkus.datasource.db-kind` and `quarkus.datasource.jdbc.url`, and logs a warning when the configured kind is another
one: it needs no database file, and loses its users and API keys at each restart. The kind is fixed at build time, so
run workers from a SQLite build. Its compaction runs on empty tables, and its dashboard stays empty.
`persistence.backend.mode` setting.

Each window is sent in at most one request per metric family. A push that fails (aggregator unreachable, rejected key)
is retried a few times on network errors, then logged and dropped: the worker does not buffer windows it could not send.
Expand Down
21 changes: 11 additions & 10 deletions doc/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ services:
With the following `application.yaml` file:

```yaml
quarkus:
datasource:
jdbc:
url: "jdbc:sqlite:/var/data/local.db"

connector:
boavizta:
uri: "http://boavizta:5000/v1/"
ecologits:
uri: "http://ecologits:80/"
persistence:
backend:
sqlite:
jdbc-url: "jdbc:sqlite:/var/data/local.db"

wombat:
connector:
boavizta:
uri: "http://boavizta:5000/v1/"
ecologits:
uri: "http://ecologits:80/"
```

And the following `monitored-environments.yaml` file:
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/tech/illuin/wombat/commons/NodeMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
public enum NodeMode
{
/** Samples its environments into its own database and serves them: the single-instance setup. */
STANDALONE,
standalone,
/** Stores and serves the metrics pushed by workers on {@code POST /api/workers/{worker}/metrics}, and samples nothing itself. */
AGGREGATOR,
aggregator,
/** Samples its environments and pushes the metrics to an aggregator instead of its own database. */
WORKER,
worker,
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import static tech.illuin.wombat.persistence.PersistenceBackendConfigSourceFactory.ACTIVE_BACKEND_CONFIG_KEY;

@StaticInitSafe
public class NodeModeConfigSourceFactory implements ConfigSourceFactory
{
public static final String AGGREGATOR = "_internal.aggregator";
public static final String AGGREGATOR_CONFIG_KEY = "_internal.aggregator";
private static final String WORKER_DB_KIND = "sqlite";
private static final String WORKER_JDBC_URL = "jdbc:sqlite::memory:";

Expand All @@ -30,18 +31,19 @@ public Iterable<ConfigSource> getConfigSources(ConfigSourceContext context)
NodeMode mode = value.getValue() == null ? null : parse(value.getValue());

Map<String, String> properties = new HashMap<>();
properties.put(AGGREGATOR, String.valueOf(mode == NodeMode.AGGREGATOR));
properties.put(AGGREGATOR_CONFIG_KEY, String.valueOf(mode == NodeMode.aggregator));

if (mode == NodeMode.WORKER)
if (mode == NodeMode.worker)
{
String dbKind = context.getValue("quarkus.datasource.db-kind").getValue();
if (dbKind != null && !dbKind.equals(WORKER_DB_KIND))
logger.warn("Worker mode only runs on SQLite: overriding quarkus.datasource.db-kind {} with {}", dbKind, WORKER_DB_KIND);
String backend = context.getValue(ACTIVE_BACKEND_CONFIG_KEY).getValue();
if (backend != null && !backend.equals(WORKER_DB_KIND))
logger.warn("Worker mode only runs on SQLite in-memory: overriding backend {} with {}", backend, WORKER_DB_KIND);

properties.put("quarkus.datasource.db-kind", WORKER_DB_KIND);
properties.put("quarkus.datasource.jdbc.url", WORKER_JDBC_URL);
properties.put("quarkus.datasource.jdbc.min-size", "1");
properties.put("quarkus.datasource.jdbc.max-size", "1");
properties.put(ACTIVE_BACKEND_CONFIG_KEY, WORKER_DB_KIND);
}

return List.of(new PropertiesConfigSource(
Expand All @@ -53,6 +55,6 @@ public Iterable<ConfigSource> getConfigSources(ConfigSourceContext context)

private static NodeMode parse(String mode)
{
return NodeMode.valueOf(mode.trim().replace('-', '_').toUpperCase(Locale.ROOT));
return NodeMode.valueOf(mode.trim().replace('-', '_').toLowerCase());
}
}
25 changes: 25 additions & 0 deletions src/main/java/tech/illuin/wombat/commons/WombatProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import tech.illuin.wombat.engine.connector.boavizta.BoaviztaProperties;
import tech.illuin.wombat.engine.connector.ecologits.EcologitsProperties;
import tech.illuin.wombat.engine.evaluation.CachedAssetEvaluatorProperties;
import tech.illuin.wombat.engine.module.extension.WombatModuleProperties;
import tech.illuin.wombat.engine.monitor.MonitorProperties;
import tech.illuin.wombat.persistence.backend.push.WorkerProperties;

@ConfigMapping(prefix = "wombat")
Expand All @@ -11,4 +16,24 @@ public interface WombatProperties
NodeMode mode();

WorkerProperties worker();

MonitorProperties monitor();

EvaluatorProperties evaluator();

WombatModuleProperties module();

ConnectorProperties connector();

interface EvaluatorProperties
{
CachedAssetEvaluatorProperties cache();
}

interface ConnectorProperties
{
BoaviztaProperties boavizta();

EcologitsProperties ecologits();
}
}
2 changes: 2 additions & 0 deletions src/main/java/tech/illuin/wombat/endpoint/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.media.SchemaProperty;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import tech.illuin.wombat.commons.WombatProperties;
import tech.illuin.wombat.endpoint.response.Response;
import tech.illuin.wombat.endpoint.response.Status;
import tech.illuin.wombat.security.AuthProperties;
import tech.illuin.wombat.endpoint.UIProperties;

import java.util.Locale;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.illuin.wombat.commons.NodeMode;
import tech.illuin.wombat.commons.NodeModeConfigSourceFactory;
import tech.illuin.wombat.core.asset.AssetIdentity;
import tech.illuin.wombat.core.source.data.MetricData;
Expand Down Expand Up @@ -42,7 +41,7 @@
* are saved.
*/
@Path("api/workers/{worker}/metrics")
@EndpointDisabled(name = NodeModeConfigSourceFactory.AGGREGATOR, stringValue = "false")
@EndpointDisabled(name = NodeModeConfigSourceFactory.AGGREGATOR_CONFIG_KEY, stringValue = "false")
@PermissionsAllowed(Permission.Names.API_METRIC_WRITE)
public class MetricController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.illuin.wombat.commons.NodeMode;
import tech.illuin.wombat.commons.NodeModeConfigSourceFactory;
import tech.illuin.wombat.core.asset.Asset;
import tech.illuin.wombat.core.asset.Environment;
Expand All @@ -34,15 +33,14 @@

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;

/**
* Receives the environments declared by workers, so an aggregator evaluates their assets without declaring them itself.
* Each worker owns the assets it declares, see {@link EnvironmentReconciler}, identified as {@code workerId.assetId}, so
* two workers declaring the same asset id declare two assets. Only an {@link NodeMode#AGGREGATOR} serves it.
*/
@Path("api/workers")
@EndpointDisabled(name = NodeModeConfigSourceFactory.AGGREGATOR, stringValue = "false")
@EndpointDisabled(name = NodeModeConfigSourceFactory.AGGREGATOR_CONFIG_KEY, stringValue = "false")
public class WorkerController
{
private final EnvironmentReconciler reconciler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Singleton;
import jakarta.ws.rs.Produces;
import tech.illuin.wombat.commons.WombatProperties;
import tech.illuin.wombat.core.connector.boavizta.connector.BoaviztaClient;
import tech.illuin.wombat.core.connector.boavizta.impact.BoaviztaEvaluationResolver;

Expand All @@ -18,19 +19,21 @@
public class BoaviztaConfig
{
@Produces @Singleton
public BoaviztaClient provideBoaviztaClient(BoaviztaProperties properties)
public BoaviztaClient provideBoaviztaClient(WombatProperties wombat)
{
BoaviztaProperties properties = wombat.connector().boavizta();
Feign.Builder builder = Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder());

if (properties.proxyUrl().isPresent() && !properties.proxyUrl().get().isBlank())
{
URI proxy = URI.create(properties.proxyUrl().get());
properties.proxyUrl().ifPresent(proxyUrl -> {
if (proxyUrl.isBlank())
return;
URI proxy = URI.create(proxyUrl);
if (proxy.getHost() == null || proxy.getPort() == -1)
throw new IllegalArgumentException("connector.boavizta.proxy-url must include a host and port, got: " + properties.proxyUrl().get());
throw new IllegalArgumentException("wombat.connector.boavizta.proxy-url must include a host and port, got: " + proxyUrl);
builder.client(new Client.Proxied(null, null, new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy.getHost(), proxy.getPort()))));
}
});

return builder.target(BoaviztaClient.class, properties.uri());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package tech.illuin.wombat.engine.connector.boavizta;

import io.smallrye.config.ConfigMapping;

import java.util.Optional;

@ConfigMapping(prefix = "connector.boavizta")
public interface BoaviztaProperties
{
String uri();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Singleton;
import jakarta.ws.rs.Produces;
import tech.illuin.wombat.commons.WombatProperties;
import tech.illuin.wombat.core.connector.ecologits.connector.EcologitsClient;

import java.net.InetSocketAddress;
Expand All @@ -17,19 +18,21 @@
public class EcologitsConfig
{
@Produces @Singleton
public EcologitsClient provideEcologitsClient(EcologitsProperties properties)
public EcologitsClient provideEcologitsClient(WombatProperties wombat)
{
EcologitsProperties properties = wombat.connector().ecologits();
Feign.Builder builder = Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder());

if (properties.proxyUrl().isPresent() && !properties.proxyUrl().get().isBlank())
{
URI proxy = URI.create(properties.proxyUrl().get());
properties.proxyUrl().ifPresent(proxyUrl -> {
if (proxyUrl.isBlank())
return;
URI proxy = URI.create(proxyUrl);
if (proxy.getHost() == null || proxy.getPort() == -1)
throw new IllegalArgumentException("connector.ecologits.proxy-url must include a host and port, got: " + properties.proxyUrl().get());
throw new IllegalArgumentException("wombat.connector.ecologits.proxy-url must include a host and port, got: " + proxyUrl);
builder.client(new Client.Proxied(null, null, new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxy.getHost(), proxy.getPort()))));
}
});

return builder.target(EcologitsClient.class, properties.uri());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package tech.illuin.wombat.engine.connector.ecologits;

import io.smallrye.config.ConfigMapping;

import java.util.Optional;

@ConfigMapping(prefix = "connector.ecologits")
public interface EcologitsProperties
{
String uri();
Expand Down
Loading
Loading