Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite1a13f1

Browse files
committed
Add collector execution task to fabric
This task will trigger the execution of a collector based on the datagroup and type that the collector will push into. This looks up theconfiguration from the performanceplatform-collector-config repo.This has been ported over from the pp-deployment repo.
1 parent58ca6cb commite1a13f1

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

‎performanceplatform.py‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
fromfabric.apiimport (task,hosts,run)
1+
importjson
2+
3+
fromfabric.apiimport (
4+
task,hosts,run,settings,
5+
sudo,get,shell_env,cd
6+
)
7+
fromStringIOimportStringIO
28

39

410
@task
@@ -23,5 +29,51 @@ def unpublish_dashboard(slug):
2329
run_stagecraft_postgres_command(sql_command)
2430

2531

32+
@task
33+
@hosts('performance-backend-1.backend')
34+
defcollect(data_group,data_type):
35+
"""Run a collector config"""
36+
base_path='/data/apps/performanceplatform-collector/current'
37+
38+
withcd(base_path):
39+
query_path='./config/queries/{}/{}.json'.format(
40+
data_group,data_type)
41+
42+
query=get_file_contents(query_path)
43+
44+
command=get_command(query_path,query)
45+
print('Executing: {}'.format(command))
46+
withsettings(sudo_user='deploy'):
47+
withshell_env(LOGLEVEL='debug'):
48+
sudo(command)
49+
50+
51+
defget_command(query_path,query):
52+
"""
53+
>>> get_command('/tmp/foo/bar', {'entrypoint': 'foo.bar.monkey', 'token': 'foo'})
54+
'./venv/bin/pp-collector -q /tmp/foo/bar -c ./config/credentials/monkey.json -t ./config/tokens/foo.json -b ./config/performanceplatform.json --console-logging'
55+
"""
56+
credentials=query['entrypoint'].split('.')[-1]
57+
58+
# realtime uses GA credentials, gcloud needs none but pp-collector fails with none
59+
ifcredentialsin ['realtime','gcloud','trending']:
60+
credentials='ga'
61+
62+
pp_collector='./venv/bin/pp-collector'
63+
credentials_path='./config/credentials/{}.json'.format(credentials)
64+
token_path='./config/tokens/{}.json'.format(
65+
query['token'])
66+
platform_path='./config/performanceplatform.json'
67+
68+
return'{} -q {} -c {} -t {} -b {} --console-logging'.format(
69+
pp_collector,query_path,credentials_path,token_path,platform_path)
70+
71+
72+
defget_file_contents(path):
73+
fd=StringIO()
74+
get(path,fd)
75+
returnjson.loads(fd.getvalue())
76+
77+
2678
defrun_stagecraft_postgres_command(sql_command):
2779
run('sudo -iu postgres psql stagecraft -c "{0}"'.format(sql_command))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp