Skip to content

Commit

Permalink
Properly decode index name to str before putting in dimension value (#67
Browse files Browse the repository at this point in the history
)

Also make tests run with python3 instead of 2.
  • Loading branch information
benkeith-splunk authored Feb 27, 2020
1 parent 8b04205 commit c0aa625
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '2'
jobs:
build:
docker:
- image: ubuntu:xenial
- image: ubuntu:bionic
working_directory: ~/code
steps:
- setup_remote_docker
Expand All @@ -12,7 +12,7 @@ jobs:
set -x
VER="17.03.0-ce"
apt-get update -q
apt-get install -yq curl python-pip
apt-get install -yq curl python3-pip
curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
mv /tmp/docker/* /usr/bin
Expand All @@ -27,8 +27,8 @@ jobs:
name: Run basic tests
working_directory: ~/code/tests
command: |
pip install pytest
pip install mock
python3 -m pip install pytest
python3 -m pip install mock
bash run_tests.sh | tee /tmp/test.log || true # The test command always exits non-zero
! grep -E 'FAILED|ERROR' /tmp/test.log > /dev/null || exit 1
- run:
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_collectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ def parse_index_stats(self, json, index_name):
result = dig_it_up(json, key.path)
# update the index name in the type_instance to include
# the index as a dimensions
name = name.format(index_name=sanitize_type_instance(index_name))
name = name.format(index_name=sanitize_type_instance(index_name).decode("utf-8"))
self.dispatch_stat(result, name, key)

def dispatch_stat(self, result, name, key, dimensions=None):
Expand Down
2 changes: 1 addition & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
PYTHON="python"
PYTHON="python3"
if [ ! -z "$1" ]; then
PYTHON="$1"
fi
Expand Down
19 changes: 11 additions & 8 deletions tests/simulate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/python

import sys
import os
import sys
from http.server import BaseHTTPRequestHandler, HTTPServer

PORT_NUMBER = 9200
Expand All @@ -14,15 +14,17 @@
print("invalid or missing directory %s" % base_path)
sys.exit(1)
else:
print("usage: ./simulate.py directory_path. Example ./simulate.py \
data/1.7.2")
print(
"usage: ./simulate.py directory_path. Example ./simulate.py \
data/1.7.2"
)
sys.exit(1)


class EsSimulatorHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.send_header("Content-type", "application/json")
self.end_headers()
self.serve_path(self.path)
return
Expand All @@ -34,13 +36,14 @@ def serve_path(self, path):
else:
file_path = file_path + ".json"
with open(file_path, "r") as f:
self.wfile.write(f.read())
self.wfile.write(f.read().encode("utf-8"))


try:
server = HTTPServer(('', PORT_NUMBER), EsSimulatorHandler)
print('Started ES simulator on port ', PORT_NUMBER)
server = HTTPServer(("", PORT_NUMBER), EsSimulatorHandler)
print("Started ES simulator on port ", PORT_NUMBER)
server.serve_forever()

except KeyboardInterrupt:
print('ctrl-c received, shutting down')
print("ctrl-c received, shutting down")
server.socket.close()

0 comments on commit c0aa625

Please sign in to comment.