Skip to content

Commit

Permalink
Fix broken Kibble (#106)
Browse files Browse the repository at this point in the history
Before this commit I got this error when running Kibble locally:
This was because https://github.com/apache/kibble/pull/83 replaced kibble.yaml with kibble.ini
This PR reads the config from `kibble.ini`.
This also adds a network to docker-compose file without which I was getting host not found error.
  • Loading branch information
kaxil authored Dec 12, 2020
1 parent 5228a4a commit e437790
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
17 changes: 17 additions & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: '3'

networks:
kibble:
driver: bridge

services:
# Helper service to setup the Apache Kibble es node
setup:
Expand All @@ -12,6 +16,8 @@ services:
- .:/kibble/
depends_on:
- elasticsearch
networks:
- kibble

# Apache Kibble API server
kibble:
Expand All @@ -25,6 +31,8 @@ services:
- .:/kibble/
depends_on:
- elasticsearch
networks:
- kibble

# Apache Kibble web ui server
ui:
Expand All @@ -36,6 +44,8 @@ services:
- 8000:8000
depends_on:
- kibble
networks:
- kibble

# Elasticsearch node required as a database for Apache Kibble
elasticsearch:
Expand All @@ -51,6 +61,8 @@ services:
ES_JAVA_OPTS: -Xms256m -Xmx256m
volumes:
- "kibble-es-data:/usr/share/elasticsearch/data"
networks:
- kibble

# Kibana to view and manage Elasticsearch
kibana:
Expand All @@ -59,6 +71,11 @@ services:
- 5601:5601
depends_on:
- elasticsearch
environment:
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
networks:
- kibble

volumes:
# named volumes can be managed easier using docker-compose
Expand Down
13 changes: 4 additions & 9 deletions kibble/api/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
import sys
import traceback

import yaml

from kibble.api.plugins import openapi
from kibble.api.plugins.database import KibbleDatabase
from kibble.api.plugins.session import KibbleSession
from kibble.settings import KIBBLE_YAML, YAML_DIRECTORY
from kibble.configuration import conf
from kibble.settings import YAML_DIRECTORY

# Compile valid API URLs from the pages library
# Allow backwards compatibility by also accepting .lua URLs
Expand All @@ -45,10 +44,6 @@
urls.append((r"^(/api/%s)(/.+)?$" % page, handler.run))


# Load Kibble master configuration
with open(KIBBLE_YAML, "r") as f:
config = yaml.safe_load(f)

# Instantiate database connections
DB = None

Expand Down Expand Up @@ -156,13 +151,13 @@ def application(environ, start_response):
Checks against the pages library, and if submod found, runs
it and returns the output.
"""
db = KibbleDatabase(config)
db = KibbleDatabase(conf)
path = environ.get("PATH_INFO", "")
for regex, function in urls:
m = re.match(regex, path)
if m:
callback = KibbleAPIWrapper(path, function)
session = KibbleSession(db, environ, config)
session = KibbleSession(db, environ, conf)
a = 0
for bucket in callback(environ, start_response, session):
if a == 0:
Expand Down
23 changes: 7 additions & 16 deletions kibble/api/plugins/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import elasticsearch

from kibble.configuration import KibbleConfigParser


class KibbleESWrapper(object):
"""
Expand Down Expand Up @@ -119,24 +121,13 @@ def count(self, index, doc_type="*", body=None):


class KibbleDatabase(object):
def __init__(self, config):
def __init__(self, config: KibbleConfigParser):
self.config = config
self.dbname = config["elasticsearch"]["dbname"]
self.dbname = config.get("elasticsearch", "dbname")
self.ES = elasticsearch.Elasticsearch(
[
{
"host": config["elasticsearch"]["host"],
"port": int(config["elasticsearch"]["port"]),
"use_ssl": config["elasticsearch"]["ssl"],
"verify_certs": False,
"url_prefix": config["elasticsearch"]["uri"]
if "uri" in config["elasticsearch"]
else "",
"http_auth": config["elasticsearch"]["auth"]
if "auth" in config["elasticsearch"]
else None,
}
],
[config.get("elasticsearch", "conn_uri")],
use_ssl=config.getboolean("elasticsearch", "ssl"),
verify_certs=False,
max_retries=5,
retry_on_timeout=True,
)
Expand Down

0 comments on commit e437790

Please sign in to comment.