Skip to content
This repository has been archived by the owner on Aug 4, 2018. It is now read-only.

Commit

Permalink
add rsyslog endpoint for pypi logs from fastly
Browse files Browse the repository at this point in the history
- Refactor pypi role into web/log
- Add Vagrant instance for pypi_log
  • Loading branch information
ewdurbin committed Dec 3, 2013
1 parent eae7f6b commit 879f60e
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 88 deletions.
12 changes: 12 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ Vagrant.configure("2") do |config|
end
end

config.vm.define "pypi_log" do |pypi_log|

pypi_log.vm.network "private_network", ip: "192.168.57.15"
pypi_log.vm.network "private_network", ip: "172.16.57.15"

pypi_log.vm.provision :salt do |s|
s.verbose = true
s.minion_config = "provisioning/salt/minion/web/pypi_log"
s.run_highstate = true
end
end

config.vm.define "mirror" do |mirror|

mirror.vm.network "private_network", ip: "192.168.57.20"
Expand Down
7 changes: 7 additions & 0 deletions provisioning/salt/minion/web/pypi_log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
file_client: local
file_roots:
base:
- /srv/salt
grains:
roles:
- pypi_log
2 changes: 1 addition & 1 deletion provisioning/salt/roots/pillar/pypi-deploys/pypi-dev.sls
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

pypi-deploy-devpypi:
name: devpypi

user: devpypi
group: devpypi
user_uid: 6666
group_gid: 6666

fastly_syslog_name: pypi-dev
path: /opt/devpypi
data_mount: /data/devpypi
data_device:
Expand Down
1 change: 1 addition & 0 deletions provisioning/salt/roots/pillar/pypi-deploys/testpypi.sls
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pypi-deploy-testpypi:
user_uid: 6666
group_gid: 6666

fastly_syslog_name: pypi-test
path: /opt/testpypi
data_mount: /data/testpypi
data_device:
Expand Down
16 changes: 16 additions & 0 deletions provisioning/salt/roots/pillar/pypi/log.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

firewall:
syslog_tcp_72:
source: 199.27.72.0/24
port: 514
syslog_tcp_77:
source: 199.27.77.0/24
port: 514
syslog_udp_72:
source: 199.27.72.0/24
port: 514
protocol: udp
syslog_udp_77:
source: 199.27.77.0/24
port: 514
protocol: udp
16 changes: 14 additions & 2 deletions provisioning/salt/roots/pillar/top.sls
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ base:

'G@roles:pypi not G@roles:develop':
- match: compound
- pypi
- pypi.web
- pypi-deploys.testpypi
- secrets.testpypi

'G@roles:pypi_log not G@roles:develop':
- match: compound
- pypi.log
- pypi-deploys.testpypi
- secrets.testpypi

'G@roles:pypi and G@roles:develop':
- match: compound
- pypi
- pypi.web
- pypi-deploys.pypi-dev
- secrets.pypi-dev

'G@roles:pypi_log and G@roles:develop':
- match: compound
- pypi.log
- pypi-deploys.pypi-dev
- secrets.pypi-dev

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pypi-deploy-testpypi:
user_uid: 6666
group_gid: 6666

fastly_syslog_name: pypitest-cdn
path: /opt/testpypi
data_mount: /data/testpypi
data_device:
Expand Down
96 changes: 96 additions & 0 deletions provisioning/salt/roots/salt/pypi/base.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

include:
- python.27.virtualenv
- python.27.m2crypto
- pkg.hg

pypi-system-deps:
pkg.installed:
- pkgs:
- python27-devel
- postgresql-devel
- gcc
- require:
- pkgrepo: python27-el6

{% set deploys = {} %}
{% for k,v in pillar.items() %}
{% if k.startswith('pypi-deploy-') %}
{% do deploys.update({k: v}) %}
{% endif %}
{% endfor %}

{% for key, config in deploys.items() %}

{{ config['name'] }}-user:
group.present:
- name: {{ config['group'] }}
- gid: {{ config['group_gid'] }}
user.present:
- name: {{ config['user'] }}
- uid: {{ config['user_uid'] }}
- gid: {{ config['group_gid'] }}
- home: {{ config['path'] }}
- createhome: True
- require:
- group: {{ config['group'] }}

{{ config['path'] }}:
file.directory:
- user: {{ config['user'] }}
- group: {{ config['group'] }}
- mode: 755

/var/log/{{ config['name'] }}:
file.directory:
- user: {{ config['user'] }}
- group: {{ config['group'] }}
- mode: 750

/var/run/{{ config['name'] }}:
file.directory:
- user: {{ config['user'] }}
- group: {{ config['group'] }}
- mode: 755

{{ config['name'] }}-source:
hg.latest:
- name: https://bitbucket.org/pypa/pypi
- rev: tip
- target: {{ config['path'] }}/src
- user: {{ config['name'] }}
- require:
- user: {{ config['name'] }}
- file: {{ config['path'] }}

/opt/{{ config['name'] }}/env:
virtualenv.managed:
- venv_bin: virtualenv-2.7
- python: python2.7
- system_site_packages: True
- user: {{ config['name'] }}
- cwd: {{ config['path'] }}/src
- requirements: {{ config['path'] }}/src/requirements.txt
- require:
- file: {{ config['path'] }}
- hg: {{ config['name'] }}-source
- user: {{ config['user'] }}
- pip: virtualenv-2.7
- pkg: python27-m2crypto
- pkg: pypi-system-deps

{{ config['path'] }}/src/config.ini:
file.managed:
- source: salt://pypi/config/pypi.ini.jinja
- user: {{ config['name'] }}
- group: {{ config['name'] }}
- mode: 640
- template: jinja
- context:
app_key: {{ key }}
- require:
- file: /var/log/{{ config['name'] }}
- file: /var/run/{{ config['name'] }}
- virtualenv: {{ config['path'] }}/env

{% endfor %}
26 changes: 26 additions & 0 deletions provisioning/salt/roots/salt/pypi/config/pypi.rsyslog.conf.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514

# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514

$ModLoad imtcp
$InputTCPServerRun 514

$ModLoad omprog
$ActionOMProgBinary {{ path }}/env/bin/rsyslog-cdn-wrapper.sh

# Don't rate-limit
$SystemLogRateLimitInterval 0

# Don't filter duplicate lines
$RepeatedMsgReduction off

# Send all logging to a process, then discard it
:app-name, isequal, "{{ syslog_name }}" :omprog:
:app-name, isequal, "{{ syslog_name }}" ~

# Turn back on filtering duplicate lines
$RepeatedMsgReduction on
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
{{ path }}/env/bin/python {{ path }}/src/tools/rsyslog-cdn.py
46 changes: 46 additions & 0 deletions provisioning/salt/roots/salt/pypi/log.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

include:
- redis
- pypi.base

rsyslog:
service:
- running
- enable: True
- restart: True
- watch:
- file: /etc/rsyslog.d/*.conf

{% set deploys = {} %}
{% for k,v in pillar.items() %}
{% if k.startswith('pypi-deploy-') %}
{% do deploys.update({k: v}) %}
{% endif %}
{% endfor %}

{% for key, config in deploys.items() %}

{{ config['path'] }}/env/bin/rsyslog-cdn-wrapper.sh:
file.managed:
- source: salt://pypi/config/rsyslog-cdn-wrapper.sh.jinja
- template: jinja
- user: {{ config['user'] }}
- group: {{ config['group'] }}
- mode: 755
- virtualenv: /opt/{{ config['name'] }}/env
- context:
path: {{ config['path'] }}
- require:
- user: {{ config['user'] }}
- group: {{ config['group'] }}
- virtualenv: /opt/{{ config['name'] }}/env

/etc/rsyslog.d/{{ config['name'] }}.conf:
file.managed:
- source: salt://pypi/config/pypi.rsyslog.conf.jinja
- template: jinja
- context:
path: {{ config['path'] }}
syslog_name: {{ config['fastly_syslog_name'] }}

{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

include:
- python.27.virtualenv
- python.27.m2crypto
- pkg.hg
- pypi.base
- nginx
- redis
- glusterfs.client
Expand All @@ -12,15 +10,6 @@ include:
- pypi.dev-db
{% endif %}

pypi-system-deps:
pkg.installed:
- pkgs:
- python27-devel
- postgresql-devel
- gcc
- require:
- pkgrepo: python27-el6

{% set deploys = {} %}
{% for k,v in pillar.items() %}
{% if k.startswith('pypi-deploy-') %}
Expand All @@ -30,38 +19,6 @@ pypi-system-deps:

{% for key, config in deploys.items() %}

{{ config['name'] }}-user:
group.present:
- name: {{ config['group'] }}
- gid: {{ config['group_gid'] }}
user.present:
- name: {{ config['user'] }}
- uid: {{ config['user_uid'] }}
- gid: {{ config['group_gid'] }}
- home: {{ config['path'] }}
- createhome: True
- require:
- group: {{ config['group'] }}

{{ config['path'] }}:
file.directory:
- user: {{ config['user'] }}
- group: {{ config['group'] }}
- mode: 755

/var/log/{{ config['name'] }}:
file.directory:
- user: {{ config['user'] }}
- group: {{ config['group'] }}
- mode: 750

/var/run/{{ config['name'] }}:
file.directory:
- user: {{ config['user'] }}
- group: {{ config['group'] }}
- mode: 755


{% if config['data_device']['type'] == "local" %}

{{ config['data_mount'] }}:
Expand Down Expand Up @@ -133,32 +90,6 @@ pypi-system-deps:
- group: root
- mode: 644

{{ config['name'] }}-source:
hg.latest:
- name: https://bitbucket.org/pypa/pypi
- rev: tip
- target: {{ config['path'] }}/src
- user: {{ config['name'] }}
- require:
- user: {{ config['name'] }}
- file: {{ config['path'] }}

/opt/{{ config['name'] }}/env:
virtualenv.managed:
- venv_bin: virtualenv-2.7
- python: python2.7
- system_site_packages: True
- user: {{ config['name'] }}
- cwd: {{ config['path'] }}/src
- requirements: {{ config['path'] }}/src/requirements.txt
- require:
- file: {{ config['path'] }}
- hg: {{ config['name'] }}-source
- user: {{ config['user'] }}
- pip: virtualenv-2.7
- pkg: python27-m2crypto
- pkg: pypi-system-deps

{{ config['path'] }}/secret:
file.directory:
- user: {{ config['name'] }}
Expand All @@ -183,20 +114,6 @@ pypi-system-deps:
- require:
- file: {{ config['path'] }}/secret

{{ config['path'] }}/src/config.ini:
file.managed:
- source: salt://pypi/config/pypi.ini.jinja
- user: {{ config['name'] }}
- group: {{ config['name'] }}
- mode: 640
- template: jinja
- context:
app_key: {{ key }}
- require:
- file: /var/log/{{ config['name'] }}
- file: /var/run/{{ config['name'] }}
- virtualenv: {{ config['path'] }}/env

/etc/init.d/{{ config['name'] }}:
file.managed:
- source: salt://pypi/config/pypi.initd.jinja
Expand Down
Loading

0 comments on commit 879f60e

Please sign in to comment.