Skip to content

Commit

Permalink
Merge pull request #719 from mlibrary/HT-DEV-1350-var-log-babel
Browse files Browse the repository at this point in the history
HathiTrust DEV-1350: /var/log/babel for web apps
  • Loading branch information
aelkiss authored Oct 8, 2024
2 parents 605e43a + cdce990 commit 75ec89e
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 75ec89e

Please sign in to comment.