Skip to content

Commit

Permalink
Fixes #RHIROS-1269 - feature flags for backend
Browse files Browse the repository at this point in the history
  • Loading branch information
upadhyeammit committed Sep 12, 2023
1 parent 052f950 commit 1d6405c
Show file tree
Hide file tree
Showing 9 changed files with 398 additions and 16 deletions.
55 changes: 55 additions & 0 deletions clowdapp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ objects:
name: ros-backend
spec:
envName: ${ENV_NAME}
featureFlags: true
dependencies:
- host-inventory
- rbac
Expand Down Expand Up @@ -63,6 +64,17 @@ objects:
value: ${DB_POOL_SIZE}
- name: DB_MAX_OVERFLOW
value: ${DB_MAX_OVERFLOW}
- name: UNLEASH_URL
value: ${UNLEASH_URL}
- name: UNLEASH_TOKEN
valueFrom:
secretKeyRef:
name: ${UNLEASH_SECRET_NAME}
key: CLIENT_ACCESS_TOKEN
optional: true
- name: BYPASS_UNLEASH
value: ${BYPASS_UNLEASH}

- name: inventory-events-processor
replicas: ${{INVENTORY_PROCESSOR_REPLICA_COUNT}}
podSpec:
Expand Down Expand Up @@ -103,6 +115,17 @@ objects:
value: ${DB_POOL_SIZE}
- name: DB_MAX_OVERFLOW
value: ${DB_MAX_OVERFLOW}
- name: UNLEASH_URL
value: ${UNLEASH_URL}
- name: UNLEASH_TOKEN
valueFrom:
secretKeyRef:
name: ${UNLEASH_SECRET_NAME}
key: CLIENT_ACCESS_TOKEN
optional: true
- name: BYPASS_UNLEASH
value: ${BYPASS_UNLEASH}

- name: engine-result-processor
replicas: ${{ENGINE_PROCESSOR_REPLICA_COUNT}}
podSpec:
Expand Down Expand Up @@ -143,6 +166,17 @@ objects:
value: ${DB_POOL_SIZE}
- name: DB_MAX_OVERFLOW
value: ${DB_MAX_OVERFLOW}
- name: UNLEASH_URL
value: ${UNLEASH_URL}
- name: UNLEASH_TOKEN
valueFrom:
secretKeyRef:
name: ${UNLEASH_SECRET_NAME}
key: CLIENT_ACCESS_TOKEN
optional: true
- name: BYPASS_UNLEASH
value: ${BYPASS_UNLEASH}

- name: garbage-collector-processor
replicas: ${{GARBAGE_COLLECTOR_REPLICA_COUNT}}
podSpec:
Expand Down Expand Up @@ -187,6 +221,17 @@ objects:
value: ${DB_POOL_SIZE}
- name: DB_MAX_OVERFLOW
value: ${DB_MAX_OVERFLOW}
- name: UNLEASH_URL
value: ${UNLEASH_URL}
- name: UNLEASH_TOKEN
valueFrom:
secretKeyRef:
name: ${UNLEASH_SECRET_NAME}
key: CLIENT_ACCESS_TOKEN
optional: true
- name: BYPASS_UNLEASH
value: ${BYPASS_UNLEASH}

database:
name: ros
version: 13
Expand Down Expand Up @@ -305,3 +350,13 @@ parameters:
value: "20"
- name: DB_MAX_OVERFLOW
value: "20"

# Feature flags
- description: Unleash secret name
name: UNLEASH_SECRET_NAME
value: bypass
- description: Unleash API url
name: UNLEASH_URL
- description: disable Unleash (feature flags), defaulting to fallback values
name: BYPASS_UNLEASH
value: 'false'
205 changes: 204 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ watchtower = ">=1.0.0"
boto3 = ">=1.16.13"
botocore = ">=1.19.13"
flask-caching = "*"
flask-unleash = "^2.0.0"

[tool.poetry.group.dev.dependencies]
flake8 = "*"
Expand Down
20 changes: 16 additions & 4 deletions ros/api/common/add_group_filter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
from ros.lib.models import System
from flask import request
from ros.lib.feature_flags import FLAG_INVENTORY_GROUPS, get_flag_value
from ros.lib.config import get_logger

logger = get_logger(__name__)


def group_filtered_query(query):
if hasattr(request, "host_groups"):
host_groups = [gid for gid in request.host_groups if gid is not None]
if len(host_groups) >= 1:
query = query.filter(System.groups[0]['id'].astext.in_(host_groups) | (System.groups == '[]'))
if get_flag_value(FLAG_INVENTORY_GROUPS):
if len(get_host_groups()) >= 1:
query = query.filter(System.groups[0]['id'].astext.in_(get_host_groups()) | (System.groups == '[]'))
else:
query = query.filter((System.groups == '[]'))
return query


def get_host_groups():
host_groups = []
try:
host_groups = [gid for gid in request.host_groups if gid is not None]
except AttributeError as e:
logger.debug(f"Can't parse the host groups, inventory groups feature is not available?: {e}")
return host_groups
Loading

0 comments on commit 1d6405c

Please sign in to comment.