+ def _build_dashboard_files(self, config: ConfigModel):
+ files_builder = FilesV3Builder()
+ files_builder.add_file(
+ "dashboard_osm.yaml",
+ Path("files/default_dashboards.yaml").read_text(),
+ )
+ if config.osm_dashboards:
+ osm_dashboards_mapping = {
+ "kafka_exporter_dashboard.json": "files/kafka_exporter_dashboard.json",
+ "mongodb_exporter_dashboard.json": "files/mongodb_exporter_dashboard.json",
+ "mysql_exporter_dashboard.json": "files/mysql_exporter_dashboard.json",
+ "nodes_exporter_dashboard.json": "files/nodes_exporter_dashboard.json",
+ "summary_dashboard.json": "files/summary_dashboard.json",
+ }
+ for file_name, path in osm_dashboards_mapping.items():
+ files_builder.add_file(file_name, Path(path).read_text())
+ return files_builder.build()
+
+ def _build_datasources_files(self):
+ files_builder = FilesV3Builder()
+ files_builder.add_file(
+ "datasource_prometheus.yaml",
+ Template(Path("files/default_datasources.yaml").read_text()).substitute(
+ prometheus_host=self.prometheus_client.hostname,
+ prometheus_port=self.prometheus_client.port,
+ ),
+ )
+ return files_builder.build()
+
+ def _check_missing_dependencies(self):
+ missing_relations = []
+
+ if self.prometheus_client.is_missing_data_in_app():
+ missing_relations.append("prometheus")
+
+ if missing_relations:
+ raise RelationsMissing(missing_relations)
+
+ def build_pod_spec(self, image_info):
+ # Validate config
+ config = ConfigModel(**dict(self.config))
+ # Check relations
+ self._check_missing_dependencies()
+ # Create Builder for the PodSpec
+ pod_spec_builder = PodSpecV3Builder()
+ # Build Container
+ container_builder = ContainerV3Builder(self.app.name, image_info)
+ container_builder.add_port(name=self.app.name, port=PORT)
+ container_builder.add_http_readiness_probe(
+ "/api/health",
+ PORT,
+ initial_delay_seconds=10,
+ period_seconds=10,
+ timeout_seconds=5,
+ failure_threshold=3,
+ )
+ container_builder.add_http_liveness_probe(
+ "/api/health",
+ PORT,
+ initial_delay_seconds=60,
+ timeout_seconds=30,
+ failure_threshold=10,
+ )
+ container_builder.add_volume_config(
+ "dashboards",
+ "/etc/grafana/provisioning/dashboards/",
+ self._build_dashboard_files(config),
+ )
+ container_builder.add_volume_config(
+ "datasources",
+ "/etc/grafana/provisioning/datasources/",
+ self._build_datasources_files(),
+ )
+ container = container_builder.build()
+ # Add container to pod spec
+ pod_spec_builder.add_container(container)
+ # Add ingress resources to pod spec if site url exists
+ if config.site_url:
+ parsed = urlparse(config.site_url)
+ annotations = {
+ "nginx.ingress.kubernetes.io/proxy-body-size": "{}".format(
+ str(config.max_file_size) + "m"
+ if config.max_file_size > 0
+ else config.max_file_size
+ ),
+ }
+ ingress_resource_builder = IngressResourceV3Builder(
+ f"{self.app.name}-ingress", annotations
+ )