Skip to content

Commit

Permalink
Introduce email connector metrics (RedHatInsights#2373)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg authored Dec 1, 2023
1 parent 2c78c8e commit 005ca53
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.redhat.cloud.notifications.connector.EngineToConnectorRouteBuilder;
import com.redhat.cloud.notifications.connector.email.config.EmailConnectorConfig;
import com.redhat.cloud.notifications.connector.email.constants.Routes;
import com.redhat.cloud.notifications.connector.email.metrics.EmailMetricsProcessor;
import com.redhat.cloud.notifications.connector.email.processors.bop.BOPRequestPreparer;
import com.redhat.cloud.notifications.connector.email.processors.recipients.RecipientsResolverRequestPreparer;
import com.redhat.cloud.notifications.connector.email.processors.recipients.RecipientsResolverResponseProcessor;
Expand Down Expand Up @@ -44,6 +45,9 @@ public class EmailRouteBuilder extends EngineToConnectorRouteBuilder {
@Inject
RecipientsResolverResponseProcessor recipientsResolverResponseProcessor;

@Inject
EmailMetricsProcessor emailMetricsProcessor;

/**
* Configures the flow for this connector.
*/
Expand Down Expand Up @@ -75,6 +79,7 @@ public void configureRoutes() {
.process(this.BOPRequestPreparer)
.to(bopEndpoint)
.log(INFO, getClass().getName(), "Sent Email notification [orgId=${exchangeProperty." + ORG_ID + "}, historyId=${exchangeProperty." + ID + "}]")
.process(emailMetricsProcessor)
.end()
.to(direct(SUCCESS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ public class ExchangeProperty {
* Holds the rendered subject contents, ready to be sent in an email.
*/
public static final String RENDERED_SUBJECT = "rendered_subject";

public static final String RECIPIENTS_SIZE = "recipientsSize";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.redhat.cloud.notifications.connector.email.metrics;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;

import static com.redhat.cloud.notifications.connector.email.constants.ExchangeProperty.RECIPIENTS_SIZE;

@ApplicationScoped
public class EmailMetricsProcessor implements Processor {

@Inject
MeterRegistry meterRegistry;

private Counter requestsCounter;
private Counter recipientsCounter;

@PostConstruct
void postConstruct() {
requestsCounter = meterRegistry.counter("notifications.connector.email.requests");
recipientsCounter = meterRegistry.counter("notifications.connector.email.recipients");
}

@Override
public void process(Exchange exchange) {
requestsCounter.increment();
int recipientsSize = exchange.getProperty(RECIPIENTS_SIZE, 0, int.class);
recipientsCounter.increment(recipientsSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void process(final Exchange exchange) {
recipients = users.stream().map(User::getEmail).collect(toSet());
Set<String> emails = exchange.getProperty(ExchangeProperty.EMAIL_RECIPIENTS, Set.class);
recipients.addAll(emails);
exchange.setProperty(ExchangeProperty.RECIPIENTS_SIZE, recipients.size());

// Prepare the email to be sent.
final Email email = new Email(
Expand Down

0 comments on commit 005ca53

Please sign in to comment.