File loki.spec of Package loki
%define realname loki
%define realver 3.4.0
%define srcext tar.gz
# turn off the generation of debuginfo rpm (RH9) ??
%global debug_package %{nil}
# Common info
Name: %{realname}
Version: %{realver}
Release: wiz%{?extraver:0.}1%{?dist}
License: AGPL-3.0
Group: System/Monitoring
URL: https://grafana.com/oss/loki/
Summary: Log aggregation system
# Install-time parameters
Recommends: logcli
# Build-time parameters
BuildRequires: go >= 1.23.5
BuildRequires: npm
BuildRequires: systemd-rpm-macros
Source0: https://codeload.github.com/grafana/loki/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}
# Config(s)
Source11: loki.sysconfig
Source12: loki.service
%description
Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation
system inspired by Prometheus. It is designed to be very cost effective and easy
to operate. It does not index the contents of the logs, but rather a set
of labels for each log stream.
Compared to other log aggregation systems, Loki:
* does not do full text indexing on logs. By storing compressed, unstructured
logs and only indexing metadata, Loki is simpler to operate and cheaper
to run.
* indexes and groups log streams using the same labels you’re already using
with Prometheus, enabling you to seamlessly switch between metrics and logs
using the same labels that you’re already using with Prometheus.
* is an especially good fit for storing Kubernetes Pod logs. Metadata such
as Pod labels is automatically scraped and indexed.
* has native support in Grafana (needs Grafana v6.0).
%package canary
Group: System/Monitoring
Summary: Application that audits the log-capturing performance of a Grafana Loki cluster
%description canary
Loki Canary is a standalone app that audits the log-capturing performance of
a Grafana Loki cluster.
This component emits and periodically queries for logs, making sure that Loki
is ingesting logs without any data loss. When something is wrong with Loki,
the Canary often provides the first indication.
Loki Canary generates artificial log lines. These log lines are sent to the
Loki cluster. Loki Canary communicates with the Loki cluster to capture metrics
about the artificial log lines, such that Loki Canary forms information about
the performance of the Loki cluster. The information is available as Prometheus
time series metrics.
%package -n logcli
Group: System/Monitoring
Summary: Command-line tool for querying and exploring logs in Grafana Loki
%description -n logcli
logcli is a command-line client for Loki that lets you run LogQL queries against
your Loki instance. The query command will output extra information about the
query and its results, such as the API URL, set of common labels, and set of
excluded labels.
This is useful, for example, if you want to download a range of logs from Loki.
Or want to perform analytical administration tasks, for example, discover the
number of log streams to understand your label cardinality, or find out the
estimated volume of data that a query will search over. You can also use logcli
as part of shell scripts.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}
%{__sed} -ri 's/CGO_ENABLED=0/CGO_ENABLED=$(CGO_ENABLED)/' Makefile
# Build step (compile/build binaries, documentation, etc)
# Note: cgo does not work with LTO
_CFLAGS="%{optflags}"
_LDFLAGS="-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro"
# Set go build variables
export GOPATH=$(pwd -P)/gomodules
export GOCACHE=$(pwd -P)/.gocache
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS="$_CFLAGS"
export CGO_CXXFLAGS="$_CFLAGS"
export CGO_LDFLAGS="$_LDFLAGS"
export GOFLAGS="-a -v -mod=vendor -buildmode=pie -gcflags=all=-dwarf=false -ldflags=all=-s"
%{__make} %{?_smp_mflags} logcli loki loki-canary \
BUILD_IN_CONTAINER=false \
CGO_ENABLED=1 \
GO_FLAGS="-a -v -mod=vendor -buildmode=pie -gcflags=all=-dwarf=false -ldflags=all=\"-s -w -linkmode=external '-extldflags=$_LDFLAGS' \$(GO_LDFLAGS)\"" \
DYN_GO_FLAGS="\$(GO_FLAGS)" \
GIT_BRANCH=master \
IMAGE_TAG=%{version} \
GIT_REVISION=refs/tags/v%{version}
# Install built stuff
%install
%{__install} -D -m0755 cmd/logcli/logcli %{buildroot}%{_bindir}/logcli
%{__install} -D -m0755 cmd/loki-canary/loki-canary %{buildroot}%{_bindir}/loki-canary
%{__install} -D -m0755 cmd/loki/loki %{buildroot}%{_bindir}/loki
%{__install} -D -m0644 %{S:11} %{buildroot}%{_sysconfdir}/sysconfig/loki
%{__install} -D -m0644 %{S:12} %{buildroot}%{_unitdir}/loki.service
%{__install} -d -m0755 %{buildroot}/var/lib/loki
%{__install} -d -m0755 %{buildroot}%{_sysconfdir}/loki
%{__sed} 's|/tmp/loki|/var/lib/loki|' cmd/loki/loki-local-config.yaml > %{buildroot}%{_sysconfdir}/loki/config.yml
# Cleanup
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
# Files list
%files
%defattr(-,root,root)
%license LICENSE LICENSING.md
%doc CHANGELOG.md README.md
%dir %{_sysconfdir}/loki
%config(noreplace) %{_sysconfdir}/loki/config.yml
%config(noreplace) %{_sysconfdir}/sysconfig/loki
%{_bindir}/loki
%{_unitdir}/loki.service
%dir %attr(0755,loki,loki) /var/lib/loki
%files canary
%defattr(-,root,root)
%license LICENSE LICENSING.md
%doc docs/sources/operations/loki-canary/_index.md
%{_bindir}/loki-canary
%files -n logcli
%defattr(-,root,root)
%license LICENSE LICENSING.md
%doc docs/sources/query/logcli/getting-started.md
%doc docs/sources/query/logcli/logcli-tutorial.md
%{_bindir}/logcli
%pre
getent group loki > /dev/null 2>&1 || groupadd -r loki
getent passwd loki > /dev/null 2>&1 || useradd -r -g loki -d /var/lib/loki -s /sbin/nologin -c "Loki user" loki
%post
%systemd_post loki.service
%preun
%systemd_preun loki.service
%postun
%systemd_postun loki.service
%changelog