Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config to result #271

Merged
merged 2 commits into from
May 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def __init__(

logger.info(f"Trying to connect to {self.name()} for {self.cluster} cluster")

self.auth_header = settings.prometheus_auth_header
self.auth_header = (
settings.prometheus_auth_header.get_secret_value() if settings.prometheus_auth_header else None
)
self.ssl_enabled = settings.prometheus_ssl_enabled

if settings.openshift:
Expand All @@ -93,7 +95,7 @@ def __init__(

logger.info(f"Using {self.name()} at {self.url} for cluster {cluster or 'default'}")

headers = settings.prometheus_other_headers
headers = {k: v.get_secret_value() for k, v in settings.prometheus_other_headers.items()}
headers |= self.additional_headers

if self.auth_header:
Expand Down Expand Up @@ -246,7 +248,9 @@ async def load_pods(self, object: K8sObjectData, period: timedelta) -> list[PodD
}}[{period_literal}]
"""
)
pod_owners = {repl_controller["metric"]["replicationcontroller"] for repl_controller in replication_controllers}
pod_owners = {
repl_controller["metric"]["replicationcontroller"] for repl_controller in replication_controllers
}
pod_owner_kind = "ReplicationController"

del replication_controllers
Expand Down
4 changes: 2 additions & 2 deletions robusta_krr/core/integrations/prometheus/prometheus_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def generate_prometheus_config(
credentials = credentials.get_frozen_credentials()
region = settings.eks_managed_prom_region if settings.eks_managed_prom_region else session.region_name
access_key = settings.eks_access_key if settings.eks_access_key else credentials.access_key
secret_key = settings.eks_secret_key if settings.eks_secret_key else credentials.secret_key
secret_key = settings.eks_secret_key.get_secret_value() if settings.eks_secret_key else credentials.secret_key
service_name = settings.eks_service_name if settings.eks_secret_key else "aps"
if not region:
raise Exception("No eks region specified")
Expand All @@ -53,7 +53,7 @@ def generate_prometheus_config(
)
# coralogix config
if settings.coralogix_token:
return CoralogixPrometheusConfig(**baseconfig, prometheus_token=settings.coralogix_token)
return CoralogixPrometheusConfig(**baseconfig, prometheus_token=settings.coralogix_token.get_secret_value())
if isinstance(metrics_service, VictoriaMetricsService):
return VictoriaMetricsPrometheusConfig(**baseconfig)
return PrometheusConfig(**baseconfig)
12 changes: 8 additions & 4 deletions robusta_krr/core/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class Config(pd.BaseSettings):

# Prometheus Settings
prometheus_url: Optional[str] = pd.Field(None)
prometheus_auth_header: Optional[str] = pd.Field(None)
prometheus_other_headers: dict[str, str] = pd.Field(default_factory=dict)
prometheus_auth_header: Optional[pd.SecretStr] = pd.Field(None)
prometheus_other_headers: dict[str, pd.SecretStr] = pd.Field(default_factory=dict)
prometheus_ssl_enabled: bool = pd.Field(False)
prometheus_cluster_label: Optional[str] = pd.Field(None)
prometheus_label: Optional[str] = pd.Field(None)
eks_managed_prom: bool = pd.Field(False)
eks_managed_prom_profile_name: Optional[str] = pd.Field(None)
eks_access_key: Optional[str] = pd.Field(None)
eks_secret_key: Optional[str] = pd.Field(None)
eks_secret_key: Optional[pd.SecretStr] = pd.Field(None)
eks_service_name: Optional[str] = pd.Field(None)
eks_managed_prom_region: Optional[str] = pd.Field(None)
coralogix_token: Optional[str] = pd.Field(None)
coralogix_token: Optional[pd.SecretStr] = pd.Field(None)
openshift: bool = pd.Field(False)

# Threading settings
Expand Down Expand Up @@ -170,6 +170,10 @@ def set_config(config: Config) -> None:
logging.getLogger("").setLevel(logging.CRITICAL)
logger.setLevel(logging.DEBUG if config.verbose else logging.CRITICAL if config.quiet else logging.INFO)

@staticmethod
def get_config() -> Optional[Config]:
return _config


# NOTE: This class is just a proxy for _config.
# Import settings from this module and use it like it is just a config object.
Expand Down
2 changes: 2 additions & 0 deletions robusta_krr/core/models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from robusta_krr.core.models.allocations import RecommendationValue, ResourceAllocations, ResourceType
from robusta_krr.core.models.objects import K8sObjectData
from robusta_krr.core.models.severity import Severity
from robusta_krr.core.models.config import Config


class Recommendation(pd.BaseModel):
Expand Down Expand Up @@ -64,6 +65,7 @@ class Result(pd.BaseModel):
description: Optional[str] = None
strategy: StrategyData
errors: list[dict[str, Any]] = pd.Field(default_factory=list)
config: Optional[Config] = pd.Field(default_factory=Config.get_config)

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
Expand Down
Loading