skekre98 commented on a change in pull request #91:
URL: https://github.com/apache/kibble/pull/91#discussion_r523121926
##########
File path: kibble/cli/setup_command.py
##########
@@ -0,0 +1,178 @@
+import os
+import sys
+import logging
+
+import click
+import tenacity
+import bcrypt
+import json
+from elasticsearch import Elasticsearch
+
+def create_es_index(
+ conn_uri: str,
+ dbname: str,
+ shards: int,
+ replicas: int,
+ admin_name: str,
+ admin_pass: str,
+ skiponexist: bool,
+):
+ """Creates Elasticsearch index used by Kibble"""
+
+ # elasticsearch logs lots of warnings on retries/connection failure
+ logging.getLogger("elasticsearch").setLevel(logging.ERROR)
+
+ mappings_json = os.path.join(
+ os.path.dirname(os.path.realpath(__file__)), "../setup/mappings.json"
+ )
+ with open(mappings_json, "r") as f:
+ mappings = json.load(f)
+
+ es = Elasticsearch([conn_uri], max_retries=5, retry_on_timeout=True)
+ print(es.info())
+
+ es_version = es.info()["version"]["number"]
+ es6 = int(es_version.split(".")[0]) >= 6
+ es7 = int(es_version.split(".")[0]) >= 7
+
+ if not es6:
+ print(
+ f"New Kibble installations require ElasticSearch 6.x or newer! "
+ f"You appear to be running {es_version}!"
+ )
+ sys.exit(-1)
+
+ # If ES >= 7, _doc is invalid and mapping should be rooted
+ if es7:
+ mappings["mappings"] = mappings["mappings"]["_doc"]
+
+ # Check if index already exists
+ if es.indices.exists(dbname + "_api"):
+ # Skip this is DB exists and -k added
+ if skiponexist:
+ print("DB prefix exists, but --skiponexist used, skipping this
step.")
+ return
+ print("Error: ElasticSearch DB prefix '%s' already exists!" % dbname)
+ sys.exit(-1)
+
+ types = [
+ "api",
+ # ci_*: CI service stats
+ "ci_build",
+ "ci_queue",
+ # code_* + evolution + file_history: git repo stats
+ "code_commit",
+ "code_commit_unique",
+ "code_modification",
+ "evolution",
+ "file_history",
+ # forum_*: forum stats (SO, Discourse, Askbot etc)
+ "forum_post",
+ "forum_topic",
+ # GitHub stats
+ "ghstats",
+ # im_*: Instant messaging stats
+ "im_stats",
+ "im_ops",
+ "im_msg",
+ "issue",
+ "logstats",
+ # email, mail*: Email statitics
+ "email",
+ "mailstats",
+ "mailtop",
+ # organisation, view, source, publish: UI Org DB
+ "organisation",
+ "view",
+ "publish",
+ "source",
+ # stats: Miscellaneous stats
+ "stats",
+ # social_*: Twitter, Mastodon, Facebook etc
+ "social_follow",
+ "social_followers",
+ "social_follower",
+ "social_person",
+ # uisession, useraccount, message: UI user DB
+ "uisession",
+ "useraccount",
+ "message",
+ # person: contributor DB
+ "person",
+ ]
+
+ for t in types:
+ iname = f"{dbname}_{t}"
+ print(f"Creating index {iname}")
+
+ settings = {"number_of_shards": shards, "number_of_replicas": replicas}
+ es.indices.create(
+ index=iname, body={"mappings": mappings["mappings"], "settings":
settings}
+ )
+ print(f"Indices created!")
Review comment:
Oh good catch. Definitely an unnecessary print.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]