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

fix: Change default port for prometheus exporter #153

Merged
merged 2 commits into from
Jan 29, 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
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
1 change: 1 addition & 0 deletions src/apt_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Apt helper module for missing features in operator_libs_linux."""

import re
from subprocess import PIPE, CalledProcessError, check_output
from typing import Optional
Expand Down
6 changes: 3 additions & 3 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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 @@ -197,7 +197,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 @@ -253,7 +253,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
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config."""

import typing as t
from enum import Enum
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/hardware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Hardware support config and command helper."""

import json
import logging
import subprocess
Expand Down
1 change: 1 addition & 0 deletions src/hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Define strategy for install, remove and verifier for different hardwares.
"""

import logging
import os
import shutil
Expand Down
1 change: 1 addition & 0 deletions src/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Exporter service helper."""

from functools import wraps
from logging import getLogger
from pathlib import Path
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 @@ -119,7 +119,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
Loading