Skip to content

Commit c8a44a9

Browse files
authored
Merge pull request #25 from CodersOfTheNight/dockerized-integration-testing
Dockerized integration testing
2 parents adf786c + 9e99852 commit c8a44a9

25 files changed

+284
-57
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pyc
2+
__pycache__/

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
language: python
22
python:
33
- 3.5
4-
- 3.6
4+
#- 3.6
5+
#- 3.7
6+
7+
services:
8+
- docker
59

610
install:
711
- python setup.py install

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
__PHONY__: all
2+
3+
pull-containers:
4+
docker-compose pull
5+
6+
rebuild-compose:
7+
docker-compose down && docker-compose build
8+
9+
run-integration-tests: pull-containers rebuild-compose
10+
docker-compose up --remove-orphans --abort-on-container-exit --exit-code-from oshino-query
11+
12+
run-dev-environment: pull-containers rebuild-compose
13+
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --remove-orphans

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ How to install
2828

2929
Quickstart
3030
==========
31-
It is highly recommended for new users to use [Quickstart Guide](quickstart.md)
31+
It is highly recommended for new users to use [Quickstart Guide](docs/quickstart.md)
3232

3333

3434
Riemann. What? Why? How?

compose/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM python:3.7-alpine
2+
3+
WORKDIR '/usr/src/oshino'
4+
5+
COPY oshino ./oshino
6+
COPY requirements ./requirements
7+
COPY tests ./tests
8+
COPY README.md ./README.md
9+
COPY setup.py .
10+
11+
COPY compose/config.yaml .
12+
13+
14+
RUN python setup.py install
15+
RUN pip install -r ./requirements/test.txt
16+
17+
CMD ["/usr/local/bin/oshino", "--config=config.yaml"]

compose/config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
interval: 5
3+
loglevel: DEBUG
4+
riemann:
5+
host: riemann
6+
port: 5555
7+
agents:
8+
- name: health-check
9+
module: oshino.agents.http_agent.HttpAgent
10+
url: https://www.python.org
11+
tag: healthcheck

docker-compose.dev.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: "3"
2+
3+
services:
4+
oshino-query:
5+
command: ["/bin/sh"]
6+
riemann:
7+
ports:
8+
- "5555:5555"
9+
- "5556:5556"
10+
riemann-ui:
11+
image: "rlister/riemann-dash"
12+
depends_on:
13+
- riemann
14+
ports:
15+
- "4567:4567"

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: "3"
2+
3+
services:
4+
oshino:
5+
build:
6+
context: .
7+
dockerfile: compose/Dockerfile
8+
depends_on:
9+
- riemann
10+
oshino-query:
11+
build:
12+
context: .
13+
dockerfile: compose/Dockerfile
14+
command: ["/usr/local/bin/pytest", "tests/it_query.py"]
15+
depends_on:
16+
- oshino
17+
- riemann
18+
riemann:
19+
image: "rlister/riemann"

oshino/agents/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from abc import ABC, abstractmethod
22

3-
from oshino.util import current_ts
3+
from oshino.util import current_ts, timer
44

55

66
class Agent(ABC):
@@ -37,15 +37,20 @@ async def process(self, event_fn):
3737
def is_valid(self):
3838
return "name" in self._data
3939

40-
async def pull_metrics(self, event_fn):
40+
async def pull_metrics(self, event_fn, loop=None):
4141
"""
4242
Method called by core.
4343
Should not be overwritten.
4444
"""
4545
if self.lazy and not self.ready:
4646
return None
47+
logger = self.get_logger()
4748

49+
ts = timer()
50+
logger.trace("Waiting for process event")
4851
result = await self.process(event_fn)
52+
td = int(timer() - ts)
53+
logger.trace("It took: {}ms".format(td))
4954
self._last_run = current_ts()
5055
return result
5156

oshino/agents/http_agent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import aiohttp
22

3-
from time import time
3+
from ..util import timer
44
from . import Agent
55

66

@@ -46,13 +46,13 @@ def translate_status(self, code):
4646

4747
async def process(self, event_fn):
4848
logger = self.get_logger()
49-
ts = time()
49+
ts = timer()
5050
state = None
5151
async with aiohttp.ClientSession() as session:
5252
async with session.get(self.url) as resp:
5353
state = self.translate_status(resp.status)
54-
te = time()
55-
span = int((te - ts) * 1000)
54+
te = timer()
55+
span = int(te - ts)
5656
logger.debug("Request to {url} returned status code {code}(as {state})"
5757
"in {span} milliseconds.".format(url=self.url,
5858
code=resp.status,

0 commit comments

Comments
 (0)