diff --git a/cookbooks/digdag/files/lib/systemd/system/promtail-digdag.service b/cookbooks/digdag/files/lib/systemd/system/promtail-digdag.service new file mode 100644 index 0000000..ca950d4 --- /dev/null +++ b/cookbooks/digdag/files/lib/systemd/system/promtail-digdag.service @@ -0,0 +1,12 @@ +[Unit] +Description=Grafana Promtail (Digdag) +Documentation=https://github.com/grafana/loki +After=network-online.target + +[Service] +User=root +Restart=always +ExecStart=/usr/local/bin/promtail --config.file=/etc/promtail/digdag.yaml + +[Install] +WantedBy=multi-user.target diff --git a/cookbooks/digdag/setup.rb b/cookbooks/digdag/setup.rb index a9abd6b..2f5e920 100644 --- a/cookbooks/digdag/setup.rb +++ b/cookbooks/digdag/setup.rb @@ -48,3 +48,26 @@ end service 'supervisor' do action :nothing end + +# Deploy /etc/hosts file: +HOSTNAME = run_command('uname -n').stdout.chomp + +template '/etc/promtail/digdag.yaml' do + owner 'root' + group 'root' + mode '644' + + variables(HOSTNAME: HOSTNAME, LOKIENDPOINT: node['promtail']['lokiendpoint']) + end + +# Deploy the `systemd` configuration: +remote_file '/lib/systemd/system/promtail-digdag.service' do + owner 'root' + group 'root' + mode '644' +end + +# Service setting: +service 'promtail-digdag' do + action [ :enable, :restart ] +end diff --git a/cookbooks/digdag/templates/etc/promtail/digdag.yaml b/cookbooks/digdag/templates/etc/promtail/digdag.yaml new file mode 100644 index 0000000..707c29b --- /dev/null +++ b/cookbooks/digdag/templates/etc/promtail/digdag.yaml @@ -0,0 +1,56 @@ +server: + disable: true + +positions: + filename: /var/opt/promtail/promtail_digdag_position.yaml + + +clients: + - url: http://<%= @LOKIENDPOINT %>/loki/api/v1/push + +scrape_configs: + - job_name: digdag + static_configs: + - targets: + - localhost + labels: + job: digdag + hostname: <%= @HOSTNAME %> + __path__: /var/log/supervisor/digdag.log + + pipeline_stages: + - match: + selector: '{job="digdag"}' + + stages: + - drop: + expression: ^[^0-9] + + - drop: + expression: ^[0-9\/]+ .*$ + + - regex: + expression: '^(?P[0-9]+\-[0-9]+\-[0-9]+ [0-9]+:[0-9]+:[0-9]+ [\+\-][0-9]+)[ :]+(\[(?P[^\])]+)\] (?P[^ ]+) [^ ]+ (?P.+))$' + + - timestamp: + source: timestamp + format: 2006-01-02 15:04:05 -0700 + + - template: + source: level + template: '{{ ToLower .level }}' + + - template: + source: level + template: '{{ regexReplaceAllLiteral "warn" .Value "warning" }}' + + - template: + source: message + template: '{{ if .message1 }} {{ .message1 }} {{ .message2 }} {{ else }} Digdag has started {{ end }}' + + - labels: + level: + + - output: + source: message +