Skip to content

Commit

Permalink
fix: Change default port for prometheus exporter (#153)
Browse files Browse the repository at this point in the history
* fix: Change default port for prometheus exporter

Change default port from 10000 to 10200 in order to avoid collisions
with the same default port in juju-backup-all.

* fix: Lint fixes due to black 24.x
  • Loading branch information
dashmage authored Jan 29, 2024
1 parent eff2431 commit 7e1df34
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
options:
exporter-port:
type: int
default: 10000
default: 10200
description: |
Start the prometheus exporter at "exporter-port". By default, it will
start at port 10000.
start at port 10200.
exporter-log-level:
type: string
default: "INFO"
Expand Down
6 changes: 3 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def _on_install_or_upgrade(self, event: ops.InstallEvent) -> None:
self.model.unit.status = BlockedStatus(err_msg)
return

port = self.model.config.get("exporter-port", "10000")
port = self.model.config.get("exporter-port", "10200")
level = self.model.config.get("exporter-log-level", "INFO")
redfish_creds = self._get_redfish_creds()
success = self.exporter.install(port, level, redfish_creds)
Expand Down Expand Up @@ -201,7 +201,7 @@ def _on_config_changed(self, event: EventBase) -> None:
}
if exporter_configs.intersection(change_set):
logger.info("Detected changes in exporter config.")
port = self.model.config.get("exporter-port", "10000")
port = self.model.config.get("exporter-port", "10200")
level = self.model.config.get("exporter-log-level", "INFO")

redfish_creds = self._get_redfish_creds()
Expand Down Expand Up @@ -257,7 +257,7 @@ def _get_redfish_creds(self) -> Dict[str, str]:

def validate_exporter_configs(self) -> Tuple[bool, str]:
"""Validate the static and runtime config options for the exporter."""
port = int(self.model.config.get("exporter-port", "10000"))
port = int(self.model.config.get("exporter-port", "10200"))
if not 1 <= port <= 65535:
logger.error("Invalid exporter-port: port must be in [1, 65535].")
return False, "Invalid config: 'exporter-port'"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_05_install_redfish_unavailable(self, mock_hw_tool_helper, mock_exporter

self.assertTrue(self.harness.charm._stored.resource_installed)

self.harness.charm.exporter.install.assert_called_with(10000, "INFO", {})
self.harness.charm.exporter.install.assert_called_with(10200, "INFO", {})

@mock.patch("charm.Exporter", return_value=mock.MagicMock())
@mock.patch("charm.HWToolHelper", return_value=mock.MagicMock())
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def test_61_config_changed_not_okay(self, mock_service_installed):
self.harness.add_relation_unit(rid, "grafana-agent/0")
# self.harness.charm.validate_exporter_configs = mock.Mock()
# self.harness.charm.validate_exporter_configs.return_value = (False, "error")
self.harness.update_config({"exporter-port": 100000, "exporter-log-level": "DEBUG"})
self.harness.update_config({"exporter-port": 102000, "exporter-log-level": "DEBUG"})
self.harness.charm.on.config_changed.emit()
self.assertEqual(
self.harness.charm.unit.status, BlockedStatus("Invalid config: 'exporter-port'")
Expand Down

0 comments on commit 7e1df34

Please sign in to comment.