Skip to content
This repository was archived by the owner on Oct 25, 2019. It is now read-only.

Commit 4b21451

Browse files
committed
use json for settings, remove stats, add tracing
1 parent fd8ca80 commit 4b21451

19 files changed

Lines changed: 286 additions & 362 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ __pycache__
2525
/*.tar
2626
/*.7z
2727
/*.tgz
28-
28+
/settings/collections.json

docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
version: "3.3"
22

3-
volumes:
4-
snoop-stats-es-data: {}
5-
63
services:
74
snoop-rabbitmq:
85
image: rabbitmq:3.7.3

src/common.py

Lines changed: 166 additions & 128 deletions
Large diffs are not rendered by default.

src/createcollection.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
collection_allowed_chars, validate_collection_name, validate_collection_data_dir, \
1010
create_settings_dir, write_collection_docker_file, volumes_dir_name, \
1111
write_python_settings_file, default_snoop_image, write_env_file, \
12-
InvalidCollectionName, exit_msg, DOCKER_HOOVER_SNOOP_STATS
12+
InvalidCollectionName, exit_msg, init_collection_settings,\
13+
write_collections_settings
1314

1415
steps_file_name = 'collection-%s-steps.txt'
1516
steps_script_name = 'init-%s.sh'
@@ -51,17 +52,12 @@ def get_args():
5152
help='Add development settings to the docker file')
5253
parser.add_argument('-p', '--profiling', action='store_const', const=True, default=False,
5354
help='Add profiling settings for the new collection.')
55+
parser.add_argument('-t', '--tracing', action='store_const', const=True, default=False,
56+
help='Add tracing settings for the new collection.')
5457
parser.add_argument('-m', '--manual-indexing', action='store_const', const=True, default=False,
5558
help='Do not add the option to start indexing automatically.')
56-
parser.add_argument('--stats', action='store_const', const=True, default=False,
57-
help='Enable kibana stats.')
5859
args = parser.parse_args()
5960

60-
try:
61-
validate_collection_name(args.collection)
62-
except InvalidCollectionName as e:
63-
exit_msg(str(e))
64-
6561
return args
6662

6763

@@ -72,26 +68,37 @@ def create_pg_dir(collection):
7268

7369

7470
def create_collection(args):
75-
data = get_collections_data(args.collection)
71+
data = get_collections_data()
72+
try:
73+
validate_collection_name(args.collection, data['collections'])
74+
except InvalidCollectionName as e:
75+
exit_msg(str(e))
7676
if len(data['collections']):
7777
validate_collections(data['collections'])
7878
validate_collection_data_dir(args.collection)
7979

8080
try:
81+
init_collection_settings(data['collections'], args.collection, {
82+
'autoindex': not args.manual_indexing,
83+
'image': args.snoop_image,
84+
'profiling': args.profiling,
85+
'tracing': args.tracing,
86+
'for_dev': args.dev,
87+
'snoop_port': data['snoop_port'],
88+
'flower_port': data['flower_port'] if not args.manual_indexing else None,
89+
'pg_port': data['pg_port'] if args.dev else None
90+
})
8191
create_pg_dir(args.collection)
8292
settings_dir = create_settings_dir(args.collection)
8393

84-
data['collections'][args.collection] = {'profiling': args.profiling, 'for_dev': args.dev}
8594
ordered_collections = OrderedDict(sorted(data['collections'].items(), key=lambda t: t[0]))
8695

87-
stats = args.stats or data['collections'].get('env', {}).get(DOCKER_HOOVER_SNOOP_STATS, False)
88-
89-
write_collection_docker_file(args.collection, args.snoop_image, settings_dir, data['snoop_port'],
90-
args.profiling, args.dev, data['pg_port'], not args.manual_indexing,
91-
stats, data['flower_port'])
92-
write_env_file(settings_dir, {'DOCKER_HOOVER_SNOOP_STATS': args.stats})
93-
write_python_settings_file(args.collection, settings_dir, args.profiling, args.dev)
94-
write_global_docker_file(ordered_collections, args.dev or bool(data['dev_instances']), stats)
96+
write_collection_docker_file(args.collection, settings_dir,
97+
data['collections'][args.collection])
98+
write_env_file(settings_dir)
99+
write_python_settings_file(args.collection, settings_dir, data['collections'][args.collection])
100+
write_global_docker_file(ordered_collections, args.dev or bool(data['dev_instances']))
101+
write_collections_settings(data)
95102
except Exception as e:
96103
print('Error creating collection: %s' % e)
97104
cleanup(args.collection)

src/listcollections.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from copy import deepcopy
33
import json
44

5-
from src.common import get_collections_data, DOCKER_HOOVER_SNOOP_STATS
5+
from src.common import get_collections_data
66

77

88
def get_args():
@@ -16,23 +16,22 @@ def print_collections(collections):
1616
index = 1
1717
for collection, settings in collections.items():
1818
print('%d. %s' % (index, collection))
19-
print(' - profiling: %s' % settings['profiling'])
20-
print(' - development: %s' % settings['for_dev'])
21-
print(' - auto-indexing: %s' % settings['autoindex'])
19+
print(' - auto-indexing: %s' % settings.get('autoindex', False))
20+
if settings.get('autoindex') and 'flower_url' in settings:
21+
print(' - flower URL: %s' % settings['flower_url'])
2222
print(' - image: %s' % settings['image'])
23-
print(' - stats: %s' % settings['stats'])
2423
print(' - snoop admin URL: %s' % settings['snoop_url'])
25-
if settings['autoindex'] and 'flower_url' in settings:
26-
print(' - flower URL: %s' % settings['flower_url'])
24+
print(' - profiling: %s' % settings.get('profiling', False))
25+
print(' - tracing: %s' % settings.get('tracing', False))
26+
print(' - development: %s' % settings.get('for_dev', False))
2727
index += 1
2828

2929

3030
def prepare_data(collections):
3131
data = deepcopy(collections)
3232
for settings in data.values():
33-
settings['stats'] = 'enabled' if settings['env'].get(DOCKER_HOOVER_SNOOP_STATS, False) \
34-
else 'disabled'
35-
del settings['env']
33+
if 'env' in settings:
34+
del settings['env']
3635
settings['snoop_url'] = 'http://localhost:%d' % settings['snoop_port']
3736
if 'flower_port' in settings:
3837
settings['flower_url'] = 'http://localhost:%d' % settings['flower_port']

src/removecollection.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,22 @@
66

77
from src.common import get_collections_data, validate_collections, cleanup, \
88
write_global_docker_file, collection_allowed_chars, validate_collection_name, \
9-
volumes_dir_name, blobs_dir_name, InvalidCollectionName, exit_msg, \
10-
DOCKER_HOOVER_SNOOP_STATS
9+
volumes_dir_name, blobs_dir_name, InvalidCollectionName, exit_msg,\
10+
write_collections_settings
1111

1212

1313
def get_args():
1414
parser = argparse.ArgumentParser(description='Remove collection.')
1515
parser.add_argument('-c', '--collection', required=True,
1616
help='Collection name; allowed characters: ' + collection_allowed_chars)
17-
parser.add_argument('--skip-index', action='store_const', const=True,
17+
parser.add_argument('-i', '--skip-index', action='store_const', const=True,
1818
help='Skip the index removal from search.')
1919
parser.add_argument('-b', '--remove-blobs', action='store_const', const=True, default=False,
2020
help='Remove blobs')
2121
parser.add_argument('-y', '--yes', action='store_const', const=True, default=False,
2222
help='Force yes answer to all interactive user inputs.')
2323
args = parser.parse_args()
2424

25-
try:
26-
validate_collection_name(args.collection)
27-
except InvalidCollectionName as e:
28-
exit_msg(str(e))
29-
3025
return args
3126

3227

@@ -63,21 +58,24 @@ def remove_blobs(collection_name, force_yes=False):
6358

6459
def remove_collection(args):
6560
data = get_collections_data()
61+
try:
62+
validate_collection_name(args.collection, data['collections'], new=False)
63+
except InvalidCollectionName as e:
64+
exit_msg(str(e))
65+
6666
if args.collection not in data['collections']:
6767
print('Invalid collection %s' % args.collection)
6868
exit(1)
6969

7070
validate_collections(data['collections'], exit_on_errors=False)
7171
if data['dev_instances'] == 1 and data['collections'][args.collection]['for_dev']:
7272
data['dev_instances'] = 0
73-
if data['stats_clients'] == 1 and \
74-
data['collections'][args.collection]['env'][DOCKER_HOOVER_SNOOP_STATS]:
75-
data['stats_clients'] = 0
7673

7774
if not args.skip_index:
7875
remove_index(args.collection)
7976
del data['collections'][args.collection]
80-
write_global_docker_file(data['collections'], bool(data['dev_instances']), bool(data['stats_clients']))
77+
write_global_docker_file(data['collections'], bool(data['dev_instances']))
78+
write_collections_settings(data['collections'])
8179

8280
cleanup(args.collection)
8381
remove_pg_dir(args.collection)

src/updatesettings.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import argparse
22

33
from src.common import validate_collections, get_collections_data, write_global_docker_file, \
4-
write_collections_docker_files, write_python_settings_files, write_env_files
4+
write_collections_docker_files, write_python_settings_files, write_env_files,\
5+
update_collections_settings, write_collections_settings,\
6+
get_collections_data_old, collections_settings_file_name
7+
import os
58

69

710
def get_args():
@@ -24,6 +27,14 @@ def get_args():
2427
help='Remove profiling settings for the given collections. ' +
2528
'If no collections were specified profiling will be disabled for all.')
2629

30+
profiling = parser.add_mutually_exclusive_group()
31+
profiling.add_argument('-t', '--tracing', action='append', nargs='*',
32+
help='Add tracing settings for the given collections. ' +
33+
'If no collections were specified the tracing will be enabled for all.')
34+
profiling.add_argument('-z', '--no-tracing', action='append', nargs='*',
35+
help='Remove tracing settings for the given collections. ' +
36+
'If no collections were specified the tracing will be disabled for all.')
37+
2738
autoindex = parser.add_mutually_exclusive_group()
2839
autoindex.add_argument('-a', '--autoindex', action='append', nargs='*',
2940
help='Enable automatic indexing for the given collections. ' +
@@ -32,13 +43,6 @@ def get_args():
3243
help='Enable automatic indexing for the given collections. ' +
3344
'If no collections were specified auto-indexing will be disabled for all.')
3445

35-
stats = parser.add_mutually_exclusive_group()
36-
stats.add_argument('--enable-stats', action='append', nargs='*',
37-
help='Enable kibana stats for the given collections. ' +
38-
'If no collections were specified kibana will be enabled for all.')
39-
stats.add_argument('--disable-stats', action='append', nargs='*',
40-
help='Disable kibana stats for the given collections. ' +
41-
'If no collections were specified kibana will be disabled for all.')
4246
return parser.parse_args()
4347

4448

@@ -58,24 +62,38 @@ def read_collections_arg(add_list, remove_list, all_collections):
5862

5963

6064
def update_settings(args):
61-
collections = get_collections_data()['collections']
65+
if not os.path.isfile(collections_settings_file_name):
66+
data = get_collections_data_old()
67+
else:
68+
data = get_collections_data()
69+
70+
collections = data['collections']
6271
if len(collections):
6372
validate_collections(collections)
6473

6574
collections_names = set(collections.keys())
75+
76+
indexing, disable_indexing = read_collections_arg(args.autoindex, args.manual_indexing,
77+
collections_names)
78+
update_collections_settings(data, {'autoindex': not disable_indexing}, indexing)
79+
6680
profiling, remove_profiling = read_collections_arg(args.profiling, args.no_profiling,
6781
collections_names)
82+
update_collections_settings(data, {'profiling': not remove_profiling}, profiling)
83+
84+
tracing, disable_tracing = read_collections_arg(args.tracing, args.no_tracing,
85+
collections_names)
86+
update_collections_settings(data, {'tracing': not disable_tracing}, tracing)
87+
6888
for_dev, remove_dev = read_collections_arg(args.dev, args.remove_dev, collections_names)
69-
indexing, disable_indexing = read_collections_arg(args.autoindex, args.manual_indexing,
70-
collections_names)
71-
stats, disable_stats = read_collections_arg(args.enable_stats, args.disable_stats, collections_names)
72-
73-
stats_clients = write_env_files(collections, stats, disable_stats)
74-
write_python_settings_files(collections, profiling, remove_profiling, for_dev, remove_dev)
75-
dev_instances = write_collections_docker_files(collections, args.snoop_image, profiling,
76-
remove_profiling, for_dev, remove_dev,
77-
indexing, disable_indexing, stats, disable_stats)
78-
write_global_docker_file(collections, bool(dev_instances), bool(stats_clients))
89+
update_collections_settings(data, {'for_dev': not remove_dev}, for_dev)
90+
91+
write_env_files(collections)
92+
93+
write_python_settings_files(collections)
94+
dev_instances = write_collections_docker_files(collections)
95+
write_global_docker_file(collections, bool(dev_instances))
96+
write_collections_settings(collections)
7997

8098
print('Restart docker-compose:')
8199
print(' $ docker-compose down && docker-compose up -d')

templates/docker-collection.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@
4040
WAIT_HOSTS_TIMEOUT: 60
4141
depends_on:
4242
- snoop-rabbitmq
43-
- snoop-tika{{ snoop_stats }}
43+
- snoop-tika
4444
- search-es
4545
- snoop-pg--{{ collection_name }}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
TRACING_ENABLED = False
3+
4+
TRACING_SERVICE = 'snoop'
5+
6+
TRACING_HOST = 'zipkin'
7+
8+
TRACING_PORT = 9411
9+
10+
TRACING_API = '/api/v2/spans'
11+

templates/snoop.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
DOCKER_HOOVER_SNOOP_SECRET_KEY={{ DOCKER_HOOVER_SNOOP_SECRET_KEY }}
22
DOCKER_HOOVER_SNOOP_DEBUG={{ DOCKER_HOOVER_SNOOP_DEBUG }}
33
DOCKER_HOOVER_SNOOP_BASE_URL={{ DOCKER_HOOVER_SNOOP_BASE_URL }}
4-
DOCKER_HOOVER_SNOOP_STATS={{ DOCKER_HOOVER_SNOOP_STATS }}
54

0 commit comments

Comments
 (0)