-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LDP backends is available for tests.But until now, no service was available in the project. We have implemented a graylog service for it.
- Loading branch information
1 parent
98c49aa
commit c68144f
Showing
16 changed files
with
187 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ class BackendTypes(Enum): | |
"""Backend types""" | ||
|
||
DATABASE = auto() | ||
LOGGING = auto() | ||
STORAGE = auto() | ||
STREAM = auto() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Base logging backend for Ralph""" | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class BaseLogging(ABC): | ||
"""Base logging backend interface""" | ||
|
||
name = "base" | ||
|
||
@abstractmethod | ||
def get(self, chunk_size=10): | ||
"""Read chunk_size records and stream them to stdout""" | ||
|
||
@abstractmethod | ||
def send(self, chunk_size=10, ignore_errors=False): | ||
"""Write chunk_size records from stdin""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Graylog storage backend for Ralph""" | ||
|
||
import itertools | ||
import logging | ||
import sys | ||
|
||
from logging_gelf.formatters import GELFFormatter | ||
from logging_gelf.handlers import GELFTCPSocketHandler | ||
|
||
from ...defaults import RALPH_GRAYLOG_HOST, RALPH_GRAYLOG_PORT | ||
from ..mixins import HistoryMixin | ||
from .base import BaseLogging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class GraylogLogging(HistoryMixin, BaseLogging): | ||
"""Graylog logging backend""" | ||
|
||
# pylint: disable=too-many-arguments | ||
|
||
name = "graylog" | ||
|
||
def __init__( | ||
self, | ||
host=RALPH_GRAYLOG_HOST, | ||
port=RALPH_GRAYLOG_PORT, | ||
client_options=None, | ||
): | ||
if client_options is None: | ||
client_options = {} | ||
|
||
self.host = host | ||
self.port = port | ||
|
||
self.gelf_logger = logging.getLogger("gelf") | ||
self.gelf_logger.setLevel(logging.INFO) | ||
|
||
def send(self, chunk_size=1, ignore_errors=False): | ||
"""Send logs in graylog backend (one JSON event per line).""" | ||
|
||
logger.debug("Logging events (chunk size: %d)", chunk_size) | ||
|
||
handler = GELFTCPSocketHandler(host=self.host, port=self.port) | ||
handler.setFormatter(GELFFormatter()) | ||
self.gelf_logger.addHandler(handler) | ||
|
||
chunks = itertools.islice(sys.stdin, chunk_size) | ||
|
||
for chunk in chunks: | ||
for event in chunk: | ||
self.gelf_logger.info(event) | ||
|
||
def get(self, chunk_size=10): | ||
"""Read chunk_size records and stream them to stdout.""" | ||
|
||
msg = "Graylog storage backend is write-only, cannot read from" | ||
logger.error(msg) | ||
raise NotImplementedError(msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Tests for Ralph base logging backend""" | ||
|
||
from ralph.backends.logging.base import BaseLogging | ||
|
||
|
||
def test_backends_logging_base_abstract_interface_with_implemented_abstract_method(): | ||
"""Tests the interface mechanism with properly implemented abstract methods.""" | ||
|
||
class GoodLogging(BaseLogging): | ||
"""Correct implementation with required abstract methods.""" | ||
|
||
name = "good" | ||
|
||
def get(self, chunk_size=10): | ||
"""Fakes the get method.""" | ||
|
||
def send(self, chunk_size=10, ignore_errors=False): | ||
"""Fakes the send method.""" | ||
|
||
GoodLogging() | ||
|
||
assert GoodLogging.name == "good" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Tests for Ralph graylog storage backend""" | ||
|
||
from ralph.backends.logging.graylog import GraylogLogging | ||
from ralph.defaults import RALPH_GRAYLOG_HOST, RALPH_GRAYLOG_PORT | ||
|
||
|
||
def test_backends_logging_graylog_logging_instantiation(): | ||
"""Tests the GraylogLogging backend instantiation.""" | ||
# pylint: disable=protected-access | ||
|
||
storage = GraylogLogging( | ||
host=RALPH_GRAYLOG_HOST, | ||
port=RALPH_GRAYLOG_PORT, | ||
) | ||
|
||
assert storage.name == "graylog" | ||
assert storage.host == "graylog" | ||
assert storage.port == 12201 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters