Skip to content

Commit

Permalink
Simplify recipients-resolver logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg committed Oct 17, 2023
1 parent af03425 commit a65ba2d
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 348 deletions.
117 changes: 54 additions & 63 deletions .rhcicd/clowdapp-recipients-resolver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,12 @@ objects:
successThreshold: 1
failureThreshold: 5
env:
- name: NOTIFICATIONS_USE_RBAC_FOR_FETCHING_USERS
value: ${NOTIFICATIONS_USE_RBAC_FOR_FETCHING_USERS}
- name: QUARKUS_REST_CLIENT_IT_S2S_KEY_STORE
value: ${IT_SERVICE_TO_SERVICE_KEY_STORE}
- name: QUARKUS_REST_CLIENT_IT_S2S_KEY_STORE_PASSWORD
valueFrom:
secretKeyRef:
name: it-services
key: it-services-keystorepassword
optional: true
- name: QUARKUS_REST_CLIENT_IT_S2S_URL
valueFrom:
secretKeyRef:
name: it-services
key: url
optional: true
- name: QUARKUS_REST_CLIENT_RBAC_S2S_READ_TIMEOUT
value: ${RBAC_S2S_READ_TIMEOUT}
- name: RBAC_SERVICE_TO_SERVICE_APPLICATION
value: ${RBAC_SERVICE_TO_SERVICE_APP}
- name: RBAC_SERVICE_TO_SERVICE_SECRET_MAP
valueFrom:
secretKeyRef:
name: rbac-psks
key: psks.json
- name: RECIPIENT_PROVIDER_IT_MAX_RESULTS_PER_PAGE
value: ${RECIPIENT_PROVIDER_IT_MAX_RESULTS_PER_PAGE}
- name: RECIPIENT_PROVIDER_RBAC_ELEMENTS_PER_PAGE
value: ${RECIPIENT_PROVIDER_RBAC_ELEMENTS_PER_PAGE}
- name: RECIPIENT_PROVIDER_USE_IT_IMPL
value: ${RECIPIENT_PROVIDER_USE_IT_IMPL}
- name: NOTIFICATIONS_RECIPIENTS_RESOLVER_MAX_RESULTS_PER_PAGE
value: ${NOTIFICATIONS_RECIPIENTS_RESOLVER_MAX_RESULTS_PER_PAGE}
- name: NOTIFICATIONS_RECIPIENTS_RESOLVER_FETCH_USERS_MBOP_ENABLED
value: ${NOTIFICATIONS_RECIPIENTS_RESOLVER_FETCH_USERS_MBOP_ENABLED}
- name: NOTIFICATIONS_RECIPIENTS_RESOLVER_FETCH_USERS_RBAC_ENABLED
value: ${NOTIFICATIONS_RECIPIENTS_RESOLVER_FETCH_USERS_RBAC_ENABLED}
- name: QUARKUS_CACHE_CAFFEINE_RBAC_RECIPIENT_USERS_PROVIDER_GET_USERS_EXPIRE_AFTER_WRITE
value: ${RBAC_USERS_RETENTION_DELAY}
- name: QUARKUS_CACHE_CAFFEINE_RBAC_RECIPIENT_USERS_PROVIDER_GET_GROUP_USERS_EXPIRE_AFTER_WRITE
Expand All @@ -102,6 +77,8 @@ objects:
value: "9000"
- name: QUARKUS_LOG_CATEGORY__COM_REDHAT_CLOUD_NOTIFICATIONS__LEVEL
value: ${NOTIFICATIONS_LOG_LEVEL}
- name: QUARKUS_LOG_CATEGORY__ORG_JBOSS_RESTEASY_REACTIVE_CLIENT_LOGGING__LEVEL
value: ${QUARKUS_LOG_CATEGORY__ORG_JBOSS_RESTEASY_REACTIVE_CLIENT_LOGGING__LEVEL}
- name: QUARKUS_LOG_CLOUDWATCH_API_CALL_TIMEOUT
value: ${QUARKUS_LOG_CLOUDWATCH_API_CALL_TIMEOUT}
- name: QUARKUS_LOG_CLOUDWATCH_BATCH_PERIOD
Expand All @@ -122,12 +99,31 @@ objects:
value: ${SENTRY_DSN}${ENV_NAME}
- name: QUARKUS_LOG_SENTRY_ENVIRONMENT
value: ${ENV_NAME}
- name: QUARKUS_REST_CLIENT_IT_S2S_KEY_STORE
value: ${IT_SERVICE_TO_SERVICE_KEY_STORE}
- name: QUARKUS_REST_CLIENT_IT_S2S_KEY_STORE_PASSWORD
valueFrom:
secretKeyRef:
name: it-services
key: it-services-keystorepassword
optional: true
- name: QUARKUS_REST_CLIENT_IT_S2S_URL
valueFrom:
secretKeyRef:
name: it-services
key: url
optional: true
- name: QUARKUS_REST_CLIENT_LOGGING_SCOPE
value: ${QUARKUS_REST_CLIENT_LOGGING_SCOPE}
- name: QUARKUS_LOG_CATEGORY__ORG_JBOSS_RESTEASY_REACTIVE_CLIENT_LOGGING__LEVEL
value: ${QUARKUS_LOG_CATEGORY__ORG_JBOSS_RESTEASY_REACTIVE_CLIENT_LOGGING__LEVEL}
- name: NOTIFICATIONS_USE_MBOP_FOR_FETCHING_USERS
value: ${NOTIFICATIONS_USE_MBOP_FOR_FETCHING_USERS}
- name: QUARKUS_REST_CLIENT_RBAC_S2S_READ_TIMEOUT
value: ${RBAC_S2S_READ_TIMEOUT}
- name: RBAC_SERVICE_TO_SERVICE_APPLICATION
value: ${RBAC_SERVICE_TO_SERVICE_APP}
- name: RBAC_SERVICE_TO_SERVICE_SECRET_MAP
valueFrom:
secretKeyRef:
name: rbac-psks
key: psks.json
parameters:
- name: CLOUDWATCH_ENABLED
description: Enable Cloudwatch (or not)
Expand All @@ -146,6 +142,11 @@ parameters:
value: quay.io/cloudservices/notifications-recipient-resolver
- name: IMAGE_TAG
value: latest
- name: IO_SMALLRYE_REACTIVE_MESSAGING_LOG_LEVEL
value: INFO
- name: IT_SERVICE_TO_SERVICE_KEY_STORE
description: "Key store for secured connection if communicating with IT. It should be set to file:/mnt/secrets/clientkeystore.jks"
value: ""
- name: MEMORY_LIMIT
description: Memory limit
value: 500Mi
Expand All @@ -157,6 +158,18 @@ parameters:
- name: NOTIFICATIONS_LOG_LEVEL
description: Log level for com.redhat.cloud.notifications
value: INFO
- name: NOTIFICATIONS_RECIPIENTS_RESOLVER_MAX_RESULTS_PER_PAGE
description: Limit value sent to the external users service while querying users.
value: "1000"
- name: NOTIFICATIONS_RECIPIENTS_RESOLVER_FETCH_USERS_MBOP_ENABLED
description: Users from an organization will be retrieved from MBOP if true
value: "false"
- name: NOTIFICATIONS_RECIPIENTS_RESOLVER_FETCH_USERS_RBAC_ENABLED
description: Users from an organization will be retrieved from RBAC if true
value: "true"
- name: QUARKUS_LOG_CATEGORY__ORG_JBOSS_RESTEASY_REACTIVE_CLIENT_LOGGING__LEVEL
description: When QUARKUS_REST_CLIENT_LOGGING_SCOPE is set to 'request-response', this logger level needs to be set to DEBUG
value: INFO
- name: QUARKUS_LOG_CLOUDWATCH_API_CALL_TIMEOUT
description: Amount of time to allow the CloudWatch client to complete the execution of an API call expressed with the ISO-8601 duration format PnDTnHnMn.nS.
value: PT30S
Expand All @@ -169,45 +182,23 @@ parameters:
- name: QUARKUS_LOG_CLOUDWATCH_MAX_QUEUE_SIZE
description: Optional maximum size of the log events queue. If this is not set, the queue will have a capacity of Integer#MAX_VALUE.
value: "100000"
- name: RBAC_S2S_READ_TIMEOUT
description: Delay in milliseconds before an RBAC S2S query is interrupted
value: "120000"
- name: QUARKUS_REST_CLIENT_LOGGING_SCOPE
description: When set to 'request-response', rest-client will log the request and response contents
value: ""
- name: RBAC_GROUP_USERS_RETENTION_DELAY
description: RBAC group users data cache retention delay. It must be expressed with the ISO-8601 duration format PnDTnHnMn.nS.
value: PT10M
- name: RBAC_S2S_READ_TIMEOUT
description: Delay in milliseconds before an RBAC S2S query is interrupted
value: "120000"
- name: RBAC_SERVICE_TO_SERVICE_APP
description: RBAC application name to use for service-to-service communication
value: notifications
- name: RBAC_USERS_RETENTION_DELAY
description: RBAC users data cache retention delay. It must be expressed with the ISO-8601 duration format PnDTnHnMn.nS.
value: PT10M
- name: RECIPIENT_PROVIDER_IT_MAX_RESULTS_PER_PAGE
description: Limit value sent to the IT API while querying users.
value: "1000"
- name: RECIPIENT_PROVIDER_RBAC_ELEMENTS_PER_PAGE
description: Limit value sent as a query param to the RBAC REST API while querying RBAC users.
value: "1000"
- name: RECIPIENT_PROVIDER_USE_IT_IMPL
description: Temporary recipients retrieval switch between RBAC and IT
value: "false"
- name: SENTRY_DSN
description: The DSN to push data to Sentry — i.e. https://public_key@host/project_id?environment=
- name: SENTRY_ENABLED
description: Enable Sentry (or not)
value: "false"
- name: NOTIFICATIONS_USE_RBAC_FOR_FETCHING_USERS
description: Users from an organization will be retrieved from RBAC if true or from the IT users service otherwise.
value: "true"
- name: IT_SERVICE_TO_SERVICE_KEY_STORE
description: "Key store for secured connection if communicating with IT. It should be set to file:/mnt/secrets/clientkeystore.jks"
value: ""
- name: IO_SMALLRYE_REACTIVE_MESSAGING_LOG_LEVEL
value: INFO
- name: QUARKUS_REST_CLIENT_LOGGING_SCOPE
description: When set to 'request-response', rest-client will log the request and response contents
value: ""
- name: QUARKUS_LOG_CATEGORY__ORG_JBOSS_RESTEASY_REACTIVE_CLIENT_LOGGING__LEVEL
description: When QUARKUS_REST_CLIENT_LOGGING_SCOPE is set to 'request-response', this logger level needs to be set to DEBUG
value: INFO
- name: NOTIFICATIONS_USE_MBOP_FOR_FETCHING_USERS
value: "false"
41 changes: 6 additions & 35 deletions recipients-resolver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,32 @@
<version>1.0.0-SNAPSHOT</version>
</parent>

<profiles>

<!--
When Maven compiles a project with the "-Dmaven.test.skip" option, the tests compilation and execution are skipped
but Maven still resolves the dependencies from the "test" scope and fails if these dependencies cannot be found.
This is considered a Maven bug by many users and even though it was reported as such several years ago, it's never
been fixed. The following profile works around that limitation and makes the compilation successful when tests are
skipped even if the listed test dependencies are not available.
-->
<profile>
<id>resolve-test-jars-if-tests-are-not-skipped</id>
<activation>
<property>
<name>maven.test.skip</name>
<value>!true</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.redhat.cloud.notifications</groupId>
<artifactId>notifications-common</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</profile>

</profiles>

<dependencies>

<!-- Scope: compile -->

<!-- Quarkus -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
<artifactId>quarkus-cache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-cache</artifactId>
<artifactId>quarkus-rest-client-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>

<!-- Quarkiverse -->
<dependency>
<groupId>io.quarkiverse.logging.cloudwatch</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,23 @@
@ApplicationScoped
public class RecipientsResolverConfig {

@ConfigProperty(name = "notifications.connector.fetch.users.rbac.enabled", defaultValue = "false")
@ConfigProperty(name = "notifications.recipients-resolver.fetch.users.rbac.enabled", defaultValue = "false")
boolean fetchUsersWithRBAC;

@ConfigProperty(name = "notifications.connector.fetch.users.mbop.enabled", defaultValue = "false")
@ConfigProperty(name = "notifications.recipients-resolver.fetch.users.mbop.enabled", defaultValue = "false")
boolean fetchUsersWithMbop;

@ConfigProperty(name = "recipients-provider.rbac.elements-per-page", defaultValue = "1000")
int rbacMaxResultsPerPage;
@ConfigProperty(name = "notifications.recipients-resolver.max-results-per-page", defaultValue = "1000")
int maxResultsPerPage;

@ConfigProperty(name = "recipients-provider.it.max-results-per-page", defaultValue = "1000")
int itMaxResultsPerPage;
@ConfigProperty(name = "notifications.recipients-resolver.retry.max-attempts", defaultValue = "3")
int maxRetryAttempts;

@ConfigProperty(name = "recipients-provider.mbop.max-results-per-page", defaultValue = "1000")
int MBOPMaxResultsPerPage;
@ConfigProperty(name = "notifications.recipients-resolver.retry.initial-backoff", defaultValue = "0.1S")
Duration initialRetryBackoff;

@ConfigProperty(name = "rbac.retry.max-attempts", defaultValue = "3")
int rbacMaxRetryAttempts;

@ConfigProperty(name = "it.retry.max-attempts", defaultValue = "3")
int itMaxRetryAttempts;

@ConfigProperty(name = "mbop.retry.max-attempts", defaultValue = "3")
int MBOPMaxRetryAttempts;

@ConfigProperty(name = "it.retry.back-off.initial-value", defaultValue = "0.1S")
Duration itInitialBackOff;

@ConfigProperty(name = "it.retry.back-off.max-value", defaultValue = "1S")
Duration itMaxBackOff;

@ConfigProperty(name = "rbac.retry.back-off.initial-value", defaultValue = "0.1S")
Duration rbacInitialBackOff;

@ConfigProperty(name = "rbac.retry.back-off.max-value", defaultValue = "1S")
Duration rbacMaxBackOff;

@ConfigProperty(name = "mbop.retry.back-off.initial-value", defaultValue = "0.1S")
Duration MBOPInitialBackOff;

@ConfigProperty(name = "mbop.retry.back-off.max-value", defaultValue = "1S")
Duration MBOPMaxBackOff;
@ConfigProperty(name = "notifications.recipients-resolver.retry.max-backoff", defaultValue = "1S")
Duration maxRetryBackoff;

@ConfigProperty(name = "mbop.apitoken", defaultValue = "na")
String mbopApiToken;
Expand All @@ -66,18 +42,10 @@ void logFeaturesStatusAtStartup(@Observes StartupEvent event) {
Log.infof("The fetching users with Rbac is %s", fetchUsersWithRBAC ? "enabled" : "disabled");
Log.infof("The fetching users with Mbop is %s", fetchUsersWithMbop ? "enabled" : "disabled");
Log.infof("The fetching users with IT Service is %s", !(fetchUsersWithRBAC || fetchUsersWithMbop) ? "enabled" : "disabled");
Log.infof("The max result per page for IT Service is %s", itMaxResultsPerPage);
Log.infof("The max result per page for Mbop is %s", MBOPMaxResultsPerPage);
Log.infof("The max result per page for Rbac is %s", rbacMaxResultsPerPage);
Log.infof("The max retry attempts for IT Service is %s", itMaxRetryAttempts);
Log.infof("The max retry attempts for Mbop is %s", MBOPMaxRetryAttempts);
Log.infof("The max retry attempts for Rbac is %s", rbacMaxRetryAttempts);
Log.infof("The retry back-off initial value for IT Service is %s", itInitialBackOff);
Log.infof("The retry back-off initial value for Mbop is %s", MBOPInitialBackOff);
Log.infof("The retry back-off initial value for Rbac is %s", rbacInitialBackOff);
Log.infof("The max retry back-off value for IT Service is %s", itMaxBackOff);
Log.infof("The max retry back-off value for MBOP is %s", MBOPMaxBackOff);
Log.infof("The max retry back-off value for rbac is %s", rbacMaxBackOff);
Log.infof("The max result per page is %s", maxResultsPerPage);
Log.infof("The max retry attempts is %s", maxRetryAttempts);
Log.infof("The retry back-off initial value is %s", initialRetryBackoff);
Log.infof("The max retry back-off value is %s", maxRetryBackoff);
Log.infof("The MBOP env is %s", mbopEnv);
}

Expand All @@ -97,52 +65,20 @@ public void setFetchUsersWithMbop(boolean fetchUsersWithMbop) {
this.fetchUsersWithMbop = fetchUsersWithMbop;
}

public Integer getRbacMaxResultsPerPage() {
return rbacMaxResultsPerPage;
}

public int getItMaxResultsPerPage() {
return itMaxResultsPerPage;
}

public int getMBOPMaxResultsPerPage() {
return MBOPMaxResultsPerPage;
}

public int getRbacMaxRetryAttempts() {
return rbacMaxRetryAttempts;
}

public int getItMaxRetryAttempts() {
return itMaxRetryAttempts;
}

public int getMBOPMaxRetryAttempts() {
return MBOPMaxRetryAttempts;
}

public Duration getItInitialBackOff() {
return itInitialBackOff;
}

public Duration getItMaxBackOff() {
return itMaxBackOff;
}

public Duration getRbacInitialBackOff() {
return rbacInitialBackOff;
public int getMaxResultsPerPage() {
return maxResultsPerPage;
}

public Duration getRbacMaxBackOff() {
return rbacMaxBackOff;
public int getMaxRetryAttempts() {
return maxRetryAttempts;
}

public Duration getMBOPInitialBackOff() {
return MBOPInitialBackOff;
public Duration getInitialRetryBackoff() {
return initialRetryBackoff;
}

public Duration getMBOPMaxBackOff() {
return MBOPMaxBackOff;
public Duration getMaxRetryBackoff() {
return maxRetryBackoff;
}

public String getMbopApiToken() {
Expand Down
Loading

0 comments on commit a65ba2d

Please sign in to comment.