Skip to content

Commit

Permalink
Update location to jenkins logs so it's together with the others (#159)
Browse files Browse the repository at this point in the history
* Update location to jenkins logs so it's together with the others

Other logs such as tasks, slaves/agents, health-checker, and sse-events.

* add debug log for loki

* logging fixes

---------

Co-authored-by: Yanks Yoon <[email protected]>
Co-authored-by: arturo-seijas <[email protected]>
Co-authored-by: Yanks Yoon <[email protected]>
  • Loading branch information
4 people committed Jul 24, 2024
1 parent c9bb193 commit e08f40f
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/reference/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ _Interface_: loki_push_api
_Supported charms_: [loki-k8s](https://charmhub.io/loki-k8s)

Logging relation provides a way to scrape logs produced from the Jenkins server charm. The Jenkins
server logs are stored at `/var/lib/jenkins/jenkins.log`. These logs are the same logs as the logs
server logs are stored at `/var/lib/jenkins/logs/jenkins.log`. These logs are the same logs as the logs
emitted to the standard output. A promtail worker is spawned and will periodically push logs to
Loki.

Expand Down
25 changes: 22 additions & 3 deletions src-docs/jenkins.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Return whether the Jenkins home directory is mounted and owned by jenkins.

---

<a href="../src/jenkins.py#L746"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L745"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `install_default_config`

Expand All @@ -103,7 +103,7 @@ Install default jenkins-config.xml.

---

<a href="../src/jenkins.py#L755"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L754"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `install_auth_proxy_config`

Expand All @@ -122,7 +122,26 @@ Install jenkins-config.xml for auth_proxy.

---

<a href="../src/jenkins.py#L858"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/jenkins.py#L763"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `install_logging_config`

```python
install_logging_config(container: Container) → None
```

Install logging config.



**Args:**

- <b>`container`</b>: The Jenkins workload container.


---

<a href="../src/jenkins.py#L867"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `get_agent_name`

Expand Down
13 changes: 11 additions & 2 deletions src/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
# The Jenkins logging configuration path
LOGGING_CONFIG_PATH = JENKINS_HOME_PATH / "logging.properties"
# The Jenkins logging path as defined in templates/logging.properties file
LOGGING_PATH = JENKINS_HOME_PATH / "jenkins.log"
LOGGING_PATH = JENKINS_HOME_PATH / "logs/jenkins.log"
# The plugins that are required for Jenkins to work
REQUIRED_PLUGINS = [
"instance-identity", # required to connect agent nodes to server
Expand Down Expand Up @@ -740,7 +740,6 @@ def _install_configs(container: ops.Container, jenkins_config_file: str) -> None
jenkins_config_file: the path to the Jenkins configuration file to install.
"""
_install_config(container, jenkins_config_file, CONFIG_FILE_PATH)
_install_config(container, JENKINS_LOGGING_CONFIG, LOGGING_CONFIG_PATH)


def install_default_config(container: ops.Container) -> None:
Expand All @@ -761,6 +760,16 @@ def install_auth_proxy_config(container: ops.Container) -> None:
_install_config(container, AUTH_PROXY_JENKINS_CONFIG, CONFIG_FILE_PATH)


def install_logging_config(container: ops.Container) -> None:
"""Install logging config.
Args:
container: The Jenkins workload container.
"""
container.make_dir(LOGGING_PATH.parent, make_parents=True, user=USER, group=GROUP)
_install_config(container, JENKINS_LOGGING_CONFIG, LOGGING_CONFIG_PATH)


def _get_groovy_proxy_args(proxy_config: state.ProxyConfig) -> typing.Iterable[str]:
"""Get proxy arguments for proxy configuration Groovy script.
Expand Down
1 change: 1 addition & 0 deletions src/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def replan_jenkins(
Raises:
JenkinsBootstrapError: if an error occurs while bootstrapping Jenkins.
"""
jenkins.install_logging_config(container=container)
container.add_layer("jenkins", _get_pebble_layer(jenkins_instance), combine=True)
container.replan()
try:
Expand Down
2 changes: 1 addition & 1 deletion templates/logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
############################################################

# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = /var/lib/jenkins/jenkins.log
java.util.logging.FileHandler.pattern = /var/lib/jenkins/logs/jenkins.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.append=true
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/test_cos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Integration tests for jenkins-k8s-operator with COS."""

import functools
import logging
import typing

import pytest
Expand All @@ -17,6 +18,8 @@
from .helpers import wait_for
from .types_ import UnitWebClient

logger = logging.getLogger(__name__)


@pytest.mark.abort_on_fail
async def test_prometheus_integration(
Expand Down Expand Up @@ -56,6 +59,7 @@ def log_files_exist(
"""
series = requests.get(f"http://{unit_address}:3100/loki/api/v1/series", timeout=10).json()
log_files = set(series_data["filename"] for series_data in series["data"])
logger.info("Loki log files: %s", log_files)
if not all(filename in log_files for filename in filenames):
return False
log_query = requests.get(
Expand Down Expand Up @@ -88,7 +92,7 @@ async def test_loki_integration(
log_files_exist,
unit.address,
application.name,
("/var/lib/jenkins/jenkins.log",),
("/var/lib/jenkins/logs/jenkins.log",),
),
timeout=10 * 60,
)
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 @@ -96,7 +96,7 @@ def test_storage_not_ready(harness: Harness, event_handler: str):

def test__on_jenkins_pebble_ready_get_version_error(
harness_container: HarnessWithContainer,
mocked_get_request: typing.Callable[[str, int, typing.Any, typing.Any], requests.Response],
mocked_get_request: typing.Callable[..., requests.Response],
monkeypatch: pytest.MonkeyPatch,
):
"""
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test__is_ready_connection_exception(
)
def test__is_ready(
monkeypatch: pytest.MonkeyPatch,
mocked_get_request: typing.Callable[[str, int, typing.Any, typing.Any], requests.Response],
mocked_get_request: typing.Callable[..., requests.Response],
status_code: int,
expected_ready: bool,
mock_env: jenkins.Environment,
Expand All @@ -66,7 +66,7 @@ def test__is_ready(

def test_wait_ready_timeout(
monkeypatch: pytest.MonkeyPatch,
mocked_get_request: typing.Callable[[str, int, typing.Any, typing.Any], requests.Response],
mocked_get_request: typing.Callable[..., requests.Response],
mock_env: jenkins.Environment,
):
"""
Expand Down Expand Up @@ -113,7 +113,7 @@ def __init__(self, *_args, **_kwargs) -> None:

def test_wait_ready(
monkeypatch: pytest.MonkeyPatch,
mocked_get_request: typing.Callable[[str, int, typing.Any, typing.Any], requests.Response],
mocked_get_request: typing.Callable[..., requests.Response],
mock_env: jenkins.Environment,
):
"""
Expand Down Expand Up @@ -356,7 +356,7 @@ def test_version_error(

def test_version(
monkeypatch: pytest.MonkeyPatch,
mocked_get_request: typing.Callable[[str, int, typing.Any, typing.Any], requests.Response],
mocked_get_request: typing.Callable[..., requests.Response],
jenkins_version: str,
mock_env: jenkins.Environment,
):
Expand All @@ -372,7 +372,7 @@ def test_version(

def test__unlock_wizard(
harness_container: HarnessWithContainer,
mocked_get_request: typing.Callable[[str, int, typing.Any, typing.Any], requests.Response],
mocked_get_request: typing.Callable[..., requests.Response],
monkeypatch: pytest.MonkeyPatch,
jenkins_version: str,
mock_env: jenkins.Environment,
Expand All @@ -397,7 +397,7 @@ def test__unlock_wizard(


def test__unlock_wizard_raises_exception(
mocked_get_request: typing.Callable[[str, int, typing.Any, typing.Any], requests.Response],
mocked_get_request: typing.Callable[..., requests.Response],
monkeypatch: pytest.MonkeyPatch,
mock_env: jenkins.Environment,
):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

def test_replan_jenkins_pebble_error(
harness_container: HarnessWithContainer,
mocked_get_request: typing.Callable[[str, int, typing.Any, typing.Any], requests.Response],
mocked_get_request: typing.Callable[..., requests.Response],
monkeypatch: pytest.MonkeyPatch,
):
"""
Expand Down

0 comments on commit e08f40f

Please sign in to comment.