use of com.redhat.cloud.notifications.models.AggregationCommand in project notifications-backend by RedHatInsights.
the class DailyEmailAggregationJob method processDailyEmail.
@ActivateRequestContext
public void processDailyEmail() {
CollectorRegistry registry = new CollectorRegistry();
Gauge duration = Gauge.build().name("aggregator_job_duration_seconds").help("Duration of the aggregator job in seconds.").register(registry);
Gauge.Timer durationTimer = duration.startTimer();
try {
LocalDateTime now = LocalDateTime.now(UTC);
List<AggregationCommand> aggregationCommands = processAggregateEmails(now, registry);
List<CompletableFuture<Void>> futures = new ArrayList<>();
for (AggregationCommand aggregationCommand : aggregationCommands) {
try {
final String payload = objectMapper.writeValueAsString(aggregationCommand);
futures.add(emitter.send(payload).toCompletableFuture());
} catch (JsonProcessingException e) {
LOG.warn("Could not transform AggregationCommand to JSON object.", e);
}
// resolve completable futures so the Quarkus main thread doesn't stop before everything has been sent
try {
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get();
} catch (InterruptedException | ExecutionException ie) {
LOG.error("Writing AggregationCommands failed", ie);
}
}
emailAggregationResources.updateLastCronJobRun(now);
Gauge lastSuccess = Gauge.build().name("aggregator_job_last_success").help("Last time the aggregator job succeeded.").register(registry);
lastSuccess.setToCurrentTime();
} finally {
durationTimer.setDuration();
PushGateway pg = new PushGateway(prometheusPushGatewayUrl);
try {
pg.pushAdd(registry, "aggregator_job");
} catch (IOException e) {
LOG.warn("Could not push metrics to Prometheus Pushgateway.", e);
}
}
}
use of com.redhat.cloud.notifications.models.AggregationCommand in project notifications-backend by RedHatInsights.
the class DailyEmailAggregationJobTest method shouldProcessOneSubscriptionOnly.
@Test
@TestTransaction
void shouldProcessOneSubscriptionOnly() {
helpers.addEmailAggregation("tenant", "someOrgId", "rhel", "policies", "somePolicyId", "someHostId");
helpers.addEmailAggregation("tenant", "someOrgId", "rhel", "policies", "somePolicyId", "someHostId");
final List<AggregationCommand> emailAggregations = testee.processAggregateEmails(LocalDateTime.now(UTC), new CollectorRegistry());
assertEquals(1, emailAggregations.size());
final AggregationCommand aggregationCommand = emailAggregations.get(0);
assertEquals("tenant", aggregationCommand.getAggregationKey().getAccountId());
assertEquals("someOrgId", aggregationCommand.getAggregationKey().getOrgId());
assertEquals("rhel", aggregationCommand.getAggregationKey().getBundle());
assertEquals("policies", aggregationCommand.getAggregationKey().getApplication());
assertEquals(DAILY, aggregationCommand.getSubscriptionType());
}
use of com.redhat.cloud.notifications.models.AggregationCommand in project notifications-backend by RedHatInsights.
the class DailyEmailAggregationJobTest method shouldNotIncreaseAggregationsWhenHostIdIsDifferent.
@Test
@TestTransaction
void shouldNotIncreaseAggregationsWhenHostIdIsDifferent() {
helpers.addEmailAggregation("someTenant", "someOrgId", "someRhel", "somePolicies", "somePolicyId", "hostId1");
helpers.addEmailAggregation("someTenant", "someOrgId", "someRhel", "somePolicies", "somePolicyId", "hostId2");
final List<AggregationCommand> emailAggregations = testee.processAggregateEmails(LocalDateTime.now(UTC), new CollectorRegistry());
assertEquals(1, emailAggregations.size());
}
use of com.redhat.cloud.notifications.models.AggregationCommand in project notifications-backend by RedHatInsights.
the class DailyEmailAggregationJobTest method shouldProcessFourSubscriptions.
@Test
@TestTransaction
void shouldProcessFourSubscriptions() {
helpers.addEmailAggregation("tenant", "someOrgId", "rhel", "policies", "somePolicyId", "someHostId");
helpers.addEmailAggregation("tenant", "someOrgId", "rhel", "unknown-application", "somePolicyId", "someHostId");
helpers.addEmailAggregation("tenant", "someOrgId", "unknown-bundle", "policies", "somePolicyId", "someHostId");
helpers.addEmailAggregation("tenant", "someOrgId", "unknown-bundle", "unknown-application", "somePolicyId", "someHostId");
final List<AggregationCommand> emailAggregations = testee.processAggregateEmails(LocalDateTime.now(UTC), new CollectorRegistry());
assertEquals(4, emailAggregations.size());
}
use of com.redhat.cloud.notifications.models.AggregationCommand in project notifications-backend by RedHatInsights.
the class DailyEmailAggregationJobTest method shouldNotIncreaseAggregationsWhenPolicyIdIsDifferent.
@Test
@TestTransaction
void shouldNotIncreaseAggregationsWhenPolicyIdIsDifferent() {
helpers.addEmailAggregation("someTenant", "someOrgId", "someRhel", "somePolicies", "policyId1", "someHostId");
helpers.addEmailAggregation("someTenant", "someOrgId", "someRhel", "somePolicies", "policyId2", "someHostId");
final List<AggregationCommand> emailAggregations = testee.processAggregateEmails(LocalDateTime.now(UTC), new CollectorRegistry());
assertEquals(1, emailAggregations.size());
}
Aggregations