Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HathiTrust DEV-1350: /var/log/babel for web apps #719

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %>
}