Skip to content

Commit

Permalink
HathiTrust DEV-1350: /var/log/babel for web apps
Browse files Browse the repository at this point in the history
Currently, the web applications log to NFS, which is suboptimal for many
reasons -- processes have to write to individual files rather than being
able to share a log file, and logs can't easily be collected from there
and sent to retention or query systems (filebeat, loki).

This:

* creates /var/log/babel and makes it writable by the web server
* adds a logrotate config to ensure logs are rotated (similar to apache
  logs)
* adds an alloy config to send these logs to loki
  • Loading branch information
aelkiss committed Oct 4, 2024
1 parent e30bcd6 commit cdce990
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
34 changes: 34 additions & 0 deletions manifests/profile/hathitrust/babel_logs.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2024 The Regents of the University of Michigan.
# All Rights Reserved. Licensed according to the terms of the Revised
# BSD License. See LICENSE.txt for details.

# nebula::profile::hathitrust::babel_logs
#
# Configure a log directory and Grafana Alloy for shipping logs from babel
# applications to loki
#
# @example
# include nebula::profile::hathitrust::babel_logs
class nebula::profile::hathitrust::babel_logs (
String $log_path = '/var/log/babel',
String $log_owner = 'nobody',
String $log_group = 'nogroup',
) {

file { $log_path:
ensure => 'directory',
owner => $log_owner,
group => $log_group,
mode => '0644'
}

file { '/etc/alloy/babel.alloy':
ensure => 'file',
content => template('nebula/profile/hathitrust/babel_logs/alloy.erb'),
}

file { '/etc/logrotate.d/babel':
ensure => 'file',
content => template('nebula/profile/hathitrust/babel_logs/logrotate.erb'),
}
}
1 change: 1 addition & 0 deletions manifests/role/webhost/htvm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
include nebula::profile::hathitrust::dependencies
include nebula::profile::hathitrust::perl
include nebula::profile::hathitrust::php
include nebula::profile::hathitrust::babel_logs

class { 'nebula::profile::hathitrust::imgsrv':
sdrview => 'full'
Expand Down
20 changes: 20 additions & 0 deletions spec/classes/profile/hathitrust/babel_logs_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Copyright (c) 2023 The Regents of the University of Michigan.
# All Rights Reserved. Licensed according to the terms of the Revised
# BSD License. See LICENSE.txt for details.
require 'spec_helper'

require_relative '../../../support/contexts/with_htvm_setup'

describe 'nebula::profile::hathitrust::babel_logs' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
it { is_expected.to compile }

it { is_expected.to contain_file('/var/log/babel').with_owner('nobody') }
it { is_expected.to contain_file('/etc/alloy/babel.alloy').with_content(%r(/var/log/babel)) }
it { is_expected.to contain_file('/etc/logrotate.d/babel').with_content(%r(/var/log/babel)) }
end
end
end
15 changes: 15 additions & 0 deletions templates/profile/hathitrust/babel_logs/alloy.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local.file_match "babel_logs" {
path_targets = [
{__path__ = "<%= @log_path %>/*.log"},
]
}

loki.source.file "babel_logs_files" {
targets = local.file_match.babel_logs.targets
forward_to = [loki.process.service__babel.receiver]
}

loki.process "service__babel" {
stage.static_labels {values = {"service" = "babel"}}
forward_to = [loki.process.hostname.receiver]
}
11 changes: 11 additions & 0 deletions templates/profile/hathitrust/babel_logs/logrotate.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= @log_path %>/*.log {
daily
missingok
rotate 7
dateext
dateyesterday
compress
delaycompress
notifempty
create 644 <%= @log_owner %> <%= @log_group %>
}

0 comments on commit cdce990

Please sign in to comment.