File opentelemetry-collector-contrib.spec of Package opentelemetry-collector-contrib

#
# spec file for package opentelemetry-collector-contrib
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define collector_short_name otelcol-contrib

Name:           opentelemetry-collector-contrib
Version:        0.127.0
Release:        0
Summary:        OpenTelemetry Collector Contrib Distribution
License:        Apache-2.0
URL:            https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
Source0:        %{name}-%{version}.tar.gz
# no Source2 for vendor.tar.gz, as the vendor directory is in the _build-%{version}.tar.xz tarball
Source3:        _build-%{version}.tar.xz
#
Source11:       %{collector_short_name}.service
Source12:       system-user-%{collector_short_name}.conf
#
Source21:       Makefile
Source22:       PACKAGING_README.md
#
BuildRequires:  golang(API) >= 1.23
BuildRequires:  ocb >= %{version}
BuildRequires:  opentelemetry-ebpf-profiler
# shell completions
BuildRequires:  bash-completion
BuildRequires:  fish
BuildRequires:  zsh
#
BuildRequires:  sysuser-tools
BuildRequires:  systemd
%if %{?suse_version} >= 1600
BuildRequires:  group(systemd-journal)
Requires:       group(systemd-journal)
%else
Requires:       systemd
%endif
%sysusers_requires
#
Provides:       %{collector_short_name} = %{version}

%description
This distribution contains all the components from both the OpenTelemetry
Collector repository and the OpenTelemetry Collector Contrib repository. This
distribution includes open source and vendor supported components.

The full list of components is available in the manifest:
https://github.com/open-telemetry/opentelemetry-collector-releases/blob/main/distributions/otelcol-contrib/manifest.yaml

%package -n %{name}-bash-completion
Summary:        Bash Completion for %{name}
Group:          System/Shells
Requires:       %{name} = %{version}
Requires:       bash-completion
Supplements:    (%{name} and bash-completion)
BuildArch:      noarch

%description -n %{name}-bash-completion
Bash command line completion support for %{name}.

%package -n %{name}-fish-completion
Summary:        Fish Completion for %{name}
Group:          System/Shells
Requires:       %{name} = %{version}
Requires:       fish
Supplements:    (%{name} and fish)
BuildArch:      noarch

%description -n %{name}-fish-completion
Fish command line completion support for %{name}.

%package -n %{name}-zsh-completion
Summary:        Zsh Completion for %{name}
Group:          System/Shells
Requires:       %{name} = %{version}
Requires:       zsh
Supplements:    (%{name} and zsh)
BuildArch:      noarch

%description -n %{name}-zsh-completion
zsh command line completion support for %{name}.

%prep
%autosetup -p 1
tar xf %{SOURCE3}
cp /usr/share/opentelemetry-ebpf-profiler/tracer* ./_build/opentelemetry-ebpf-profiler/support/ebpf/
ls -lah ./_build/opentelemetry-ebpf-profiler/support/ebpf/tracer*
sleep 5

%build
# hash will be shortended by COMMIT_HASH:0:8 later
COMMIT_HASH="$(sed -n 's/commit: \(.*\)/\1/p' %_sourcedir/%{name}.obsinfo)"

DATE_FMT="+%%Y-%%m-%%dT%%H:%%M:%%SZ"
BUILD_DATE=$(date -u -d "@${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "${DATE_FMT}" 2>/dev/null || date -u "${DATE_FMT}")

%ifnarch ppc64
export GOFLAGS="-buildmode=pie"
%endif
ocb \
        --config distributions/%{collector_short_name}/manifest.yaml \
        --skip-generate \
        --skip-get-modules

# system user
%sysusers_generate_pre %{SOURCE12} user

%install
# Install the binary.
install -D -m 0755 ./_build/%{collector_short_name} %{buildroot}%{_bindir}/%{collector_short_name}

# systemd unit
install -D -m 0644 %{SOURCE11} %{buildroot}%{_unitdir}/%{collector_short_name}.service

# configuration directory
install -d -m 0755 %{buildroot}%{_sysconfdir}/%{collector_short_name}/

# environment file
install -D -m 0644 distributions/%{collector_short_name}/%{collector_short_name}.conf %{buildroot}%{_sysconfdir}/default/%{collector_short_name}

# working directory
install -d -m 0770 %{buildroot}%{_sharedstatedir}/%{collector_short_name}/
install -d -m 0770 %{buildroot}%{_sharedstatedir}/%{collector_short_name}/data/

# create the bash completion file
mkdir -p %{buildroot}%{_datarootdir}/bash-completion/completions/
%{buildroot}%{_bindir}/%{collector_short_name} completion bash > %{buildroot}%{_datarootdir}/bash-completion/completions/%{collector_short_name}

# create the fish completion file
mkdir -p %{buildroot}%{_datarootdir}/fish/vendor_completions.d/
%{buildroot}%{_bindir}/%{collector_short_name} completion fish > %{buildroot}%{_datarootdir}/fish/vendor_completions.d/%{collector_short_name}.fish

# create the zsh completion file
mkdir -p %{buildroot}%{_datarootdir}/zsh/site-functions/
%{buildroot}%{_bindir}/%{collector_short_name} completion zsh > %{buildroot}%{_datarootdir}/zsh/site-functions/_%{collector_short_name}

#
install -Dm644 %{SOURCE12} %{buildroot}%{_sysusersdir}/system-user-%{collector_short_name}.conf

%check
%{buildroot}%{_bindir}/%{collector_short_name} --version

%pre -f user.pre
%service_add_pre %{collector_short_name}.service

%post
%service_add_post %{collector_short_name}.service

%preun
%service_del_preun %{collector_short_name}.service

%postun
%service_del_postun %{collector_short_name}.service

%files
%doc README.md
%license LICENSE
%{_bindir}/%{collector_short_name}
%{_unitdir}/%{collector_short_name}.service

# directories in /var/lib/
%dir %attr(770,%{collector_short_name},%{collector_short_name}) %{_sharedstatedir}/%{collector_short_name}/
%dir %attr(770,%{collector_short_name},%{collector_short_name}) %{_sharedstatedir}/%{collector_short_name}/data/

# directory in /etc/
%dir %attr(770,root,%{collector_short_name}) %config %{_sysconfdir}/%{collector_short_name}
%ghost %attr(640,root,%{collector_short_name}) %config(noreplace) %{_sysconfdir}/%{collector_short_name}/config.yaml

# environment file
%attr(640,root,%{collector_short_name}) %config(noreplace) %{_sysconfdir}/default/%{collector_short_name}

# system user
%{_sysusersdir}/system-user-%{collector_short_name}.conf

%files -n %{name}-bash-completion
%{_datarootdir}/bash-completion/completions/%{collector_short_name}

%files -n %{name}-fish-completion
%{_datarootdir}/fish/vendor_completions.d/%{collector_short_name}.fish

%files -n %{name}-zsh-completion
%{_datarootdir}/zsh/site-functions/_%{collector_short_name}

%changelog
openSUSE Build Service is sponsored by