Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1818670 - Review Request: sensu-go - Sensu Go Open Source (Monitoring Program) [NEEDINFO]
Summary: Review Request: sensu-go - Sensu Go Open Source (Monitoring Program)
Keywords:
Status: ASSIGNED
Alias: None
Product: Fedora
Classification: Fedora
Component: Package Review
Version: rawhide
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Robert-André Mauchin 🐧
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: FE-NEEDSPONSOR
TreeView+ depends on / blocked
 
Reported: 2020-03-30 04:18 UTC by Devin Acosta
Modified: 2021-06-29 18:22 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: ---
Embargoed:
zebob.m: fedora-review?
zebob.m: needinfo? (devin)


Attachments (Terms of Use)

Description Devin Acosta 2020-03-30 04:18:30 UTC
Spec URL: https://github.com/devinacosta/sensugo-koji/blob/master/rpmbuild/SPECS/sensu-go.spec
SRPM URL: https://kojipkgs.fedoraproject.org//work/tasks/5993/42855993/sensu-go-5.18.1-1.el7.src.rpm

Description:
Sensu is an open source monitoring tool for ephemeral infrastructure and distributed applications. It is an agent based monitoring system with built-in auto-discovery, making it very well-suited for cloud environments. Sensu uses service checks to monitor service health and collect telemetry data. It also has a number of well defined APIs for configuration, external data input, and to provide access to Sensu's data. Sensu is extremely extensible and is commonly referred to as "the monitoring router".

Fedora Account System Username: devinacosta

Notes:

I have been asked by Sensu Inc, if I wouldn't mind helping them by maintaining Sensu Go (Open Source Edition) for them, so we can get it included into EPEL. I have successfully built the RPMS, even though I know my Spec file may need a little additional work.
In order to get Sensu to compile, i had to TAR up the 70+ Go Modules needed and extract it.

My first successful build is at:
https://koji.fedoraproject.org/koji/taskinfo?taskID=42855993

Comment 1 Weiping 2020-03-30 13:13:22 UTC
(In reply to Devin Acosta from comment #0)
> Spec URL:
> https://github.com/devinacosta/sensugo-koji/blob/master/rpmbuild/SPECS/sensu-
> go.spec

This is a informal review:
Please use raw format for github, there is a raw button, like
https://raw.githubusercontent.com/devinacosta/sensugo-koji/master/rpmbuild/SPECS/sensu-go.spec

Comment 2 Zbigniew Jędrzejewski-Szmek 2020-03-31 21:09:51 UTC
The description is supposed to go in the spec file primarily. (Usually the one in the
review request is just a copy. What counts is the one in the file.)
Please wrap it to 80 columns when copying into the file.

Sources should be extracted in %prep, not in %build.

The scripts to add 'sensu' user and group need to be a bit different:
please use the scriptlet from
https://docs.fedoraproject.org/en-US/packaging-guidelines/UsersAndGroups/#_dynamic_allocation

Users cannot be removed from the system, because this generally cannot be done safely.
Also, do not remove non-cache data on package removal. 

The scriptlets to define the user should be present in just one subpackage,
and the other subpackage should Require it. If both packages are fully independent
and both need the user, add a comment to the spec file about that.

The %postun systemd scriptlets are missing, see
https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_scriptlets

You can drop full paths like in /usr/sbin/userdel. Both /usr/bin and /usr/sbin
are guaranteed to be in the path.

There is also no gain in using macros like %{__install}. They serve no purpose whatsoever
and make the spec file much harder to read.
(There is a guidelines to use macros for some _directories_, because they change occasionally,
but binary names don't change.)

Systemd unit files go to /usr/lib/systemd/system, not in etc, see
https://www.freedesktop.org/software/systemd/man/systemd.unit.html#Description.

/var/run/sensu/ → /run/sensu. It also needs %ghost.
https://docs.fedoraproject.org/en-US/packaging-guidelines/#_run

BuildRequires: systemd
→ systemd-rpm-macros should be enough, it is much more lightweight.

> Group:          Development/Languages
Not necessary, please remove.

Requires(post):     systemd
Requires(preun):    systemd
Requires(postun):   systemd
→ not necessary, should be removed.

Following https://docs.fedoraproject.org/en-US/packaging-guidelines/Golang/#_dependencies,
please add:
BuildRequires: go-rpm-macros.

The big question at the end: would it be possible to unbundle any of the
go dependencies, i.e. to use some packages from Fedora. It seems that doing that
for all 70+ modules is infeasible, but maybe a partial unbundling would work. I
don't know about go to have an informed opinion. If everything is bundled, this
needs a comment in the spec file and justification.

Comment 3 Zbigniew Jędrzejewski-Szmek 2020-04-01 09:06:06 UTC
(In reply to Zbigniew Jędrzejewski-Szmek from comment #2)
> /var/run/sensu/ → /run/sensu. It also needs %ghost.
> https://docs.fedoraproject.org/en-US/packaging-guidelines/#_run

I saw that you asked about this on IRC.
/var/run is a symlink to /run, so using the /var/run path anywhere doesn't make much sense.
Usually, it's just a longer and uglier legacy name. It also matters in one particular case:
when /var is separately mounted. In that case, /var/run cannot be resolved before /var is
mounted, so using /var/run creates an ordering dependency.

Both in case of /var/run/foo and /run/foo, the directory is stored on a tmpfs, so
it doesn't survive reboots. Rpm needs to be told that this is the case, by adding %ghost
in the %file list, so that e.g. 'rpm -V' doesn't complain about a missing directory.

Comment 4 Devin Acosta 2020-04-07 21:59:33 UTC
I have spent a little over an entire week making lots of modifications per your request. I changed the following:

- Removed my cleanup jobs so they don't delete users, or cleanup any directories
- I fixed my installation section to all use common (install -m xxx) method.
- I cleaned up a lot of the  %files, %attr() section, also fixed the /var/run issue I ran into, which i talked in IRC channel about.
- I had it end up creating 3 RPMS like the Sensu Enterprise edition does to keep in-line with what they are doing.
- I fixed the dynamic user creation as requested.

The only thing that I have yet to really tackle is the way that I am TARing up the Go Dependencies and just extracting them (since the Koji) doesn't allow for external access to download the modules it needs to compile. I am still working on seeing what options i have there to clean up the code a little bit more.

please check out my latest SPEC file located at:
https://raw.githubusercontent.com/devinacosta/sensugo-koji/master/rpmbuild/SPECS/sensu-go.spec

Also You can see my latest build output here:
https://koji.fedoraproject.org/koji/taskinfo?taskID=43104293

Let me know if you have more suggestions or if i missed anything?

Comment 5 Dominik 'Rathann' Mierzejewski 2020-04-20 20:14:04 UTC
%define debug_package %{nil} is no-go, a proper debug{info,source} packages must be generated. See https://docs.fedoraproject.org/en-US/packaging-guidelines/Debuginfo/ .

Fedora has Golang specific guidelines at https://docs.fedoraproject.org/en-US/packaging-guidelines/Golang/ .

Is there any reason why you're not following them?

The empty %check section is useless. Please either run some after-build tests there or drop it. Golang guidelines mention a %gochecks macro which runs built-in tests in a standard way.

ExclusiveArch: x86_64 is not justified, please see: https://docs.fedoraproject.org/en-US/packaging-guidelines/#_architecture_support

As for bundling so many build dependencies, this is something that should be avoided in general: https://docs.fedoraproject.org/en-US/packaging-guidelines/#bundling .

Please make an effort to unbundle them first. This may require submitting additional packages for review.

I can sponsor you, but this package requires a bit more work to pass review. It would also help if you could do a couple of informal reviews of other pending packages.

Comment 6 Devin Acosta 2020-05-06 15:50:22 UTC
Dominik,

I will see what I can do to try to adhere to the Go way of doing things, however I am not a GoLang developer by any means. The Go Binary that I am building requires 79 additional Go Language dependencies, so it seems like a huge task for me to have to maintain 79 additional packages in addition to the one that I am trying to get added to EPEL 7/EPEL 8. 

For Example this is all the required GoLang dependencies as of right now. So seems like the Fedora way would say that I have to create 79 packages for each one of these requirements? I understand why bundling everything with the package can be not optimal but seems like a really steep hill to try to have to maintain 79 other packages in addition. Maybe why no one YET has tried to get Sensu Go into EPEL because of the requirements. 

Thoughts?

github.com/AlecAivazis/survey v1.4.1
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/NYTimes/gziphandler v0.0.0-20180227021810-5032c8878b9d
github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f // indirect
github.com/ash2k/stager v0.0.0-20170622123058-6e9c7b0eacd4 // indirect
github.com/atlassian/gostatsd v0.0.0-20180514010436-af796620006e
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.17+incompatible
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f
github.com/dave/jennifer v0.0.0-20171207062344-d8bdbdbee4e1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/docker/docker v0.0.0-20180409082103-cbde00b44273
github.com/echlebek/crock v1.0.1
github.com/echlebek/timeproxy v1.0.0
github.com/emicklei/proto v1.1.0
github.com/frankban/quicktest v1.7.2 // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-ole/go-ole v0.0.0-20170209151332-de8695c8edbf // indirect
github.com/go-resty/resty/v2 v2.1.0
github.com/gogo/protobuf v1.3.1
github.com/golang/groupcache v0.0.0-20191002201903-404acd9df4cc // indirect
github.com/golang/protobuf v1.3.2
github.com/google/uuid v1.1.1
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f // indirect
github.com/gorilla/mux v1.6.2
github.com/gorilla/websocket v1.4.1
github.com/gotestyourself/gotestyourself v2.2.0+incompatible // indirect
github.com/graph-gophers/dataloader v0.0.0-20180104184831-78139374585c
github.com/graphql-go/graphql v0.7.9-0.20191125031726-2e2b648ecbe4
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.11.3 // indirect
github.com/gxed/GoEndian v0.0.0-20160916112711-0f5c6873267e // indirect
github.com/gxed/eventfd v0.0.0-20160916113412-80a92cca79a8 // indirect
github.com/hashicorp/go-version v1.2.0
github.com/ipfs/go-log v0.0.0-20180416040000-7ecd3df29a4a // indirect
github.com/jbenet/go-reuseport v0.0.0-20180416043609-15a1cd37f050 // indirect
github.com/json-iterator/go v1.1.7
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/libp2p/go-reuseport v0.0.0-20180416043609-15a1cd37f050 // indirect
github.com/libp2p/go-sockaddr v0.0.0-20180329070516-f3e9f73a53d1 // indirect
github.com/mattn/go-colorable v0.0.9 // indirect
github.com/mattn/go-isatty v0.0.2 // indirect
github.com/mattn/go-runewidth v0.0.2 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
github.com/mholt/archiver/v3 v3.3.1-0.20191129193105-44285f7ed244
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.1.2
github.com/olekukonko/tablewriter v0.0.0-20180506121414-d4647c9c7a84
github.com/prometheus/client_golang v1.2.0
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4
github.com/robertkrimen/otto v0.0.0-20180617131154-15f95af6e78d
github.com/robfig/cron/v3 v3.0.0
github.com/sensu/lasr v1.2.1
github.com/shirou/gopsutil v0.0.0-20180801053943-8048a2e9c577
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.4.0
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc // indirect
github.com/willf/pad v0.0.0-20160331131008-b3d780601022
go.etcd.io/bbolt v1.3.2
go.uber.org/multierr v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582
golang.org/x/sys v0.0.0-20191113165036-4c7a9d0fe056
golang.org/x/text v0.3.2 // indirect
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 // indirect
google.golang.org/grpc v1.24.0
gopkg.in/AlecAivazis/survey.v1 v1.4.0 // indirect
gopkg.in/h2non/filetype.v1 v1.0.3
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v2 v2.2.4
gotest.tools v2.2.0+incompatible // indirect
sigs.k8s.io/yaml v1.1.0

Comment 7 Robert-André Mauchin 🐧 2020-06-23 21:27:24 UTC
Most of these are already packaged, the work to be done would be low. Anyhow EPEL would need to be vendored as we don't have macros available there.

A few remarks:

 - You need a logrotate file for your log

 - Don't use /opt for the home of the Sensu user, but %{_sharedstatedir}/sensu:

%pre backend
getent group sensu >/dev/null || groupadd -r sensu
getent passwd sensu >/dev/null || \
    useradd -r -g sensu -d %{_sharedstatedir}/sensu -s /sbin/nologin \
    -c "Sensu User" sensu
exit 0

%pre agent
getent group sensu >/dev/null || groupadd -r sensu
getent passwd sensu >/dev/null || \
    useradd -r -g sensu -d %{_sharedstatedir}/sensu -s /sbin/nologin \
    -c "Sensu User" sensu
exit 0

 - You should use macros for the various directories used in the SPEC:

%install
install -m 0755 -vd                     %{buildroot}%{_sbindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_sbindir}/

install -m 0755 -vd                     %{buildroot}%{_tmpfilesdir}
install -m 0755 -vd                     %{buildroot}%{_unitdir}
install -m 0755 -vd                     %{buildroot}%{_sysconfdir}/sensu
install -m 0755 -vd                     %{buildroot}%{_sharedstatedir}/sensu
install -m 0755 -vd                     %{buildroot}%{_localstatedir}/cache/sensu
install -m 0755 -vd                     %{buildroot}%{_localstatedir}/log/sensu
install -m 0755 -vd                     %{buildroot}%{_rundir}/sensu
install -m 0755 -vd                     %{buildroot}%{_sysconfdir}/logrotate.d
install -pm 0644 %{SOURCE2}             %{buildroot}%{_unitdir}/sensu-backend.service
install -pm 0640 %{SOURCE4}             %{buildroot}%{_sysconfdir}/sensu/backend.yml
install -pm 0644 %{SOURCE3}             %{buildroot}%{_unitdir}/sensu-agent.service
install -pm 0640 %{SOURCE5}             %{buildroot}%{_sysconfdir}/sensu/agent.yml
install -pm 0644 %{SOURCE6}             %{buildroot}%{_tmpfilesdir}/%{name}.conf
install -pm 0644 %{SOURCE7}             %{buildroot}%{_sysconfdir}/logrotate.d/%{name}.conf


Here are SPEC to use bundled dependencies:

First for Fedora: https://koji.fedoraproject.org/koji/taskinfo?taskID=46060718

=====================================================================================================
# Generated by go2rpm 1
%bcond_without check
%bcond_without vendor

# https://github.com/sensu/sensu-go
%global goipath         github.com/sensu/sensu-go
Version:                5.21.0

%gometa

%global common_description %{expand:
Sensu is an open source monitoring tool for ephemeral infrastructure and
distributed applications. It is an agent based monitoring system with built-in
auto-discovery, making it very well-suited for cloud environments. Sensu uses
service checks to monitor service health and collect telemetry data. It also has
a number of well defined APIs for configuration, external data input, and to
provide access to Sensu's data. Sensu is extremely extensible and is commonly
referred to as "the monitoring router".}

%global golicenses      LICENSE
%global godocs          CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md\\\
                        FAQ.md README.md

Name:           sensu-go
Release:        3%{?dist}
Summary:        Simple, Scalable, Multi-cloud monitoring

License:        MIT
URL:            %{gourl}
Source0:        %{gosource}
# git clone https://github.com/sensu/sensu-go
# cd sensu-go
# git checkout v%%{version}
# go mod vendor
# tar czvf vendor-%%{version}.tar.gz vendor/
Source1:        vendor-%{version}.tar.gz
Source2:        sensu-backend.service
Source3:        sensu-agent.service
Source4:        backend.yml
Source5:        agent.yml
Source6:        %{name}-tmpfiles.conf
Source7:        %{name}-logrotate.conf

BuildRequires:  systemd-rpm-macros
Requires:       logrotate
Requires(pre):  shadow-utils

%if %{without vendor}
BuildRequires:  golang(github.com/AlecAivazis/survey)
BuildRequires:  golang(github.com/atlassian/gostatsd)
BuildRequires:  golang(github.com/atlassian/gostatsd/pkg/statsd)
BuildRequires:  golang(github.com/coreos/etcd/clientv3)
BuildRequires:  golang(github.com/coreos/etcd/clientv3/concurrency)
BuildRequires:  golang(github.com/coreos/etcd/embed)
BuildRequires:  golang(github.com/coreos/etcd/etcdserver/api/v3client)
BuildRequires:  golang(github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes)
BuildRequires:  golang(github.com/coreos/etcd/etcdserver/etcdserverpb)
BuildRequires:  golang(github.com/coreos/etcd/mvcc/mvccpb)
BuildRequires:  golang(github.com/coreos/etcd/pkg/transport)
BuildRequires:  golang(github.com/coreos/etcd/pkg/types)
BuildRequires:  golang(github.com/coreos/etcd/store)
BuildRequires:  golang(github.com/coreos/etcd/version)
BuildRequires:  golang(github.com/coreos/pkg/capnslog)
BuildRequires:  golang(github.com/dave/jennifer/jen)
BuildRequires:  golang(github.com/dgrijalva/jwt-go)
BuildRequires:  golang(github.com/docker/docker/pkg/term)
BuildRequires:  golang(github.com/echlebek/timeproxy)
BuildRequires:  golang(github.com/emicklei/proto)
BuildRequires:  golang(github.com/ghodss/yaml)
BuildRequires:  golang(github.com/go-resty/resty/v2)
BuildRequires:  golang(github.com/gogo/protobuf/gogoproto)
BuildRequires:  golang(github.com/gogo/protobuf/proto)
BuildRequires:  golang(github.com/golang/protobuf/proto)
BuildRequires:  golang(github.com/golang/snappy)
BuildRequires:  golang(github.com/google/uuid)
BuildRequires:  golang(github.com/gorilla/mux)
BuildRequires:  golang(github.com/gorilla/websocket)
BuildRequires:  golang(github.com/graph-gophers/dataloader)
BuildRequires:  golang(github.com/graphql-go/graphql)
BuildRequires:  golang(github.com/graphql-go/graphql/gqlerrors)
BuildRequires:  golang(github.com/graphql-go/graphql/language/ast)
BuildRequires:  golang(github.com/graphql-go/graphql/language/location)
BuildRequires:  golang(github.com/graphql-go/graphql/language/parser)
BuildRequires:  golang(github.com/graphql-go/graphql/language/source)
BuildRequires:  golang(github.com/hashicorp/go-version)
BuildRequires:  golang(github.com/json-iterator/go)
BuildRequires:  golang(github.com/mgutz/ansi)
BuildRequires:  golang(github.com/mholt/archiver/v3)
BuildRequires:  golang(github.com/mitchellh/go-homedir)
BuildRequires:  golang(github.com/mitchellh/mapstructure)
BuildRequires:  golang(github.com/NYTimes/gziphandler)
BuildRequires:  golang(github.com/olekukonko/tablewriter)
BuildRequires:  golang(github.com/prometheus/client_golang/prometheus)
BuildRequires:  golang(github.com/prometheus/client_golang/prometheus/promhttp)
BuildRequires:  golang(github.com/prometheus/client_model/go)
BuildRequires:  golang(github.com/robertkrimen/otto)
BuildRequires:  golang(github.com/robertkrimen/otto/parser)
BuildRequires:  golang(github.com/robfig/cron/v3)
BuildRequires:  golang(github.com/sensu/lasr)
BuildRequires:  golang(github.com/shirou/gopsutil/host)
BuildRequires:  golang(github.com/shirou/gopsutil/net)
BuildRequires:  golang(github.com/sirupsen/logrus)
BuildRequires:  golang(github.com/spf13/cobra)
BuildRequires:  golang(github.com/spf13/pflag)
BuildRequires:  golang(github.com/spf13/viper)
BuildRequires:  golang(github.com/stretchr/testify/mock)
BuildRequires:  golang(github.com/stretchr/testify/require)
BuildRequires:  golang(github.com/willf/pad/utf8)
BuildRequires:  golang(go.etcd.io/bbolt)
BuildRequires:  golang(golang.org/x/crypto/bcrypt)
BuildRequires:  golang(golang.org/x/net/context)
BuildRequires:  golang(golang.org/x/time/rate)
BuildRequires:  golang(google.golang.org/grpc)
BuildRequires:  golang(google.golang.org/grpc/grpclog)
BuildRequires:  golang(gopkg.in/h2non/filetype.v1)
BuildRequires:  golang(gopkg.in/h2non/filetype.v1/types)
BuildRequires:  golang(gopkg.in/yaml.v2)

%if %{with check}
# Tests
BuildRequires:  golang(github.com/coreos/etcd/integration)
BuildRequires:  golang(github.com/echlebek/crock)
BuildRequires:  golang(github.com/gogo/protobuf/jsonpb)
BuildRequires:  golang(github.com/graphql-go/graphql/testutil)
BuildRequires:  golang(github.com/prometheus/client_golang/prometheus/testutil)
BuildRequires:  golang(github.com/stretchr/testify/assert)
%endif
%endif

%description
%{common_description}

%package backend
Summary: Sensu Go Backend Service

%description backend
The Sensu backend is a service that manages check requests and event data.
Every Sensu backend includes an integrated transport for scheduling checks
using subscriptions, an event processing pipeline that applies filters,
mutators, and handlers, an embedded etcd datastore for storing configuration
and state, a Sensu API, a Sensu dashboard, and the sensu-backend command line
tool.

%package agent
Summary: Sensu Go Agent Service

%description agent
The Sensu agent is a lightweight client that runs on the infrastructure
components you want to monitor.  Agents register with the Sensu backend as
monitoring entities with type: "agent". Agent entities are responsible for
creating check and metrics events to send to the backend event pipeline.

%package cli
Summary: Sensu Go CLI

%description cli
The Sensu GO (sensuctl) command line utility to interact with Sensu Go Backend.

%prep
%goprep %{?with_vendor: -k}
%if %{with vendor}
%setup -q -T -D -a 1 -n %{extractdir}
%endif

%build
export LDFLAGS="-X \"github.com/sensu/sensu-go/version.Version=%{version}+oss_fc%fedora\" \
                -X \"github.com/sensu/sensu-go/version.BuildDate=`date +%Y-%m-%d`\""
for cmd in cmd/* ; do
  %gobuild -o %{gobuilddir}/bin/$(basename $cmd) %{goipath}/$cmd
done
rm -f %{gobuilddir}/bin/loadit

%install
install -m 0755 -vd                     %{buildroot}%{_sbindir}
install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_sbindir}/

install -m 0755 -vd                     %{buildroot}%{_tmpfilesdir}
install -m 0755 -vd                     %{buildroot}%{_unitdir}
install -m 0755 -vd                     %{buildroot}%{_sysconfdir}/sensu
install -m 0755 -vd                     %{buildroot}%{_sharedstatedir}/sensu
install -m 0755 -vd                     %{buildroot}%{_localstatedir}/cache/sensu
install -m 0755 -vd                     %{buildroot}%{_localstatedir}/log/sensu
install -m 0755 -vd                     %{buildroot}%{_rundir}/sensu
install -m 0755 -vd                     %{buildroot}%{_sysconfdir}/logrotate.d
install -pm 0644 %{SOURCE2}             %{buildroot}%{_unitdir}/sensu-backend.service
install -pm 0640 %{SOURCE4}             %{buildroot}%{_sysconfdir}/sensu/backend.yml
install -pm 0644 %{SOURCE3}             %{buildroot}%{_unitdir}/sensu-agent.service
install -pm 0640 %{SOURCE5}             %{buildroot}%{_sysconfdir}/sensu/agent.yml
install -pm 0644 %{SOURCE6}             %{buildroot}%{_tmpfilesdir}/%{name}.conf
install -pm 0644 %{SOURCE7}             %{buildroot}%{_sysconfdir}/logrotate.d/%{name}.conf

%if %{with check}
%check
%gocheck -t api/core/v2
%endif

%pre backend
getent group sensu >/dev/null || groupadd -r sensu
getent passwd sensu >/dev/null || \
    useradd -r -g sensu -d %{_sharedstatedir}/sensu -s /sbin/nologin \
    -c "Sensu User" sensu
exit 0

%pre agent
getent group sensu >/dev/null || groupadd -r sensu
getent passwd sensu >/dev/null || \
    useradd -r -g sensu -d %{_sharedstatedir}/sensu -s /sbin/nologin \
    -c "Sensu User" sensu
exit 0

%post backend
%systemd_post sensu-backend.service

%post agent
%systemd_post sensu-agent.service

%preun backend
%systemd_preun sensu-backend.service

%preun agent
%systemd_preun sensu-agent.service

%postun backend
%systemd_postun sensu-backend.service

%postun agent
%systemd_postun sensu-agent.service


%files cli
%license LICENSE
%doc CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md FAQ.md README.md
%{_sbindir}/sensuctl

%files backend
%license LICENSE
%attr(-,sensu,sensu) %dir %{_sharedstatedir}/sensu/
%attr(755, sensu, sensu) %dir %{_sysconfdir}/sensu/
%attr(755, sensu, sensu) %dir %{_localstatedir}/cache/sensu/
%attr(755, sensu, sensu) %dir %{_localstatedir}/log/sensu/
%ghost %attr(755, sensu, sensu) %{_rundir}/sensu/
%config(noreplace) %attr(644, sensu, sensu) %{_sysconfdir}/sensu/backend.yml
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf
%{_unitdir}/sensu-backend.service
%{_sbindir}/sensu-backend
%{_tmpfilesdir}/%{name}.conf
%exclude %{_sysconfdir}/sensu/agent.yml

%files agent
%license LICENSE
%attr(-,sensu,sensu) %dir /var/lib/sensu/
%attr(755, sensu, sensu) %dir %{_sysconfdir}/sensu/
%attr(755, sensu, sensu) %dir %{_localstatedir}/cache/sensu/
%attr(755, sensu, sensu) %dir %{_localstatedir}/log/sensu/
%ghost %attr(755, sensu, sensu) %{_rundir}/sensu/
%config(noreplace) %attr(644, sensu, sensu) %{_sysconfdir}/sensu/agent.yml
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf
%{_unitdir}/sensu-agent.service
%{_sbindir}/sensu-agent
%{_tmpfilesdir}/%{name}.conf
%exclude %{_sysconfdir}/sensu/backend.yml

%changelog
* Wed Apr 01 2020 Devin Acosta <devin> - 5.21.0-3
- Fixed Configs being overwritten, added +oss_el7|8 to version

* Sun Mar 29 2020 Devin Acosta <devin> - 5.21.0-2
- Added SPEC to create sensu-go-backend/sensu-go-agent RPMS

* Sun Mar 29 2020 Devin Acosta <devin> - 5.21.0-1
- Initial package

=====================================================================================================

For EPEL7: https://koji.fedoraproject.org/koji/taskinfo?taskID=46060716
EPEL8: https://koji.fedoraproject.org/koji/taskinfo?taskID=46060714

=====================================================================================================
%define gobuild(o:) %{expand:
  # https://bugzilla.redhat.com/show_bug.cgi?id=995136#c12
  %global _dwz_low_mem_die_limit 0
  %ifnarch ppc64
  go build -buildmode pie -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}' -compressdwarf=false" -a -v -x %{?**};
  %else
  go build                -compiler gc -tags="rpm_crashtraceback ${BUILDTAGS:-}" -ldflags "${LDFLAGS:-}%{?currentgoldflags} -B 0x$(head -c20 /dev/urandom|od -An -tx1|tr -d ' \\n') -extldflags '%__global_ldflags %{?__golang_extldflags}' -compressdwarf=false" -a -v -x %{?**};
  %endif
}

# https://github.com/sensu/sensu-go
%global goipath         github.com/sensu/sensu-go
Version:                5.21.0

%global common_description %{expand:
Sensu is an open source monitoring tool for ephemeral infrastructure and
distributed applications. It is an agent based monitoring system with built-in
auto-discovery, making it very well-suited for cloud environments. Sensu uses
service checks to monitor service health and collect telemetry data. It also has
a number of well defined APIs for configuration, external data input, and to
provide access to Sensu's data. Sensu is extremely extensible and is commonly
referred to as "the monitoring router".}

%global golicenses      LICENSE
%global godocs          CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md\\\
                        FAQ.md README.md

Name:           sensu-go
Release:        3%{?dist}
Summary:        Simple, Scalable, Multi-cloud monitoring

License:        MIT
URL:            https://github.com/sensu/sensu-go
Source0:        https://github.com/sensu/sensu-go/archive/v%{version}/%{name}-%{version}.tar.gz
# git clone https://github.com/sensu/sensu-go
# cd sensu-go
# git checkout v%%{version}
# go mod vendor
# tar czvf vendor-%%{version}.tar.gz vendor/
Source1:        vendor-%{version}.tar.gz
Source2:        sensu-backend.service
Source3:        sensu-agent.service
Source4:        backend.yml
Source5:        agent.yml
Source6:        %{name}-tmpfiles.conf
Source7:        %{name}-logrotate.conf

# e.g. el6 has ppc64 arch without gcc-go, so EA tag is required
ExclusiveArch:  %{?go_arches:%{go_arches}}%{!?go_arches:%{ix86} x86_64 aarch64 %{arm}}
# If go_compiler is not set to 1, there is no virtual provide. Use golang instead.
BuildRequires:  %{?go_compiler:compiler(go-compiler)}%{!?go_compiler:golang}

%if 0%{?el7}
BuildRequires:  systemd
%else
BuildRequires:  systemd-rpm-macros
%endif
Requires:       logrotate
Requires(pre):  shadow-utils

%description
%{common_description}

%package backend
Summary: Sensu Go Backend Service

%description backend
The Sensu backend is a service that manages check requests and event data.
Every Sensu backend includes an integrated transport for scheduling checks
using subscriptions, an event processing pipeline that applies filters,
mutators, and handlers, an embedded etcd datastore for storing configuration
and state, a Sensu API, a Sensu dashboard, and the sensu-backend command line
tool.

%package agent
Summary: Sensu Go Agent Service

%description agent
The Sensu agent is a lightweight client that runs on the infrastructure
components you want to monitor.  Agents register with the Sensu backend as
monitoring entities with type: "agent". Agent entities are responsible for
creating check and metrics events to send to the backend event pipeline.

%package cli
Summary: Sensu Go CLI

%description cli
The Sensu GO (sensuctl) command line utility to interact with Sensu Go Backend.

%prep
%autosetup -p1 -n %{name}-%{version}
%setup -q -T -D -a 1 -n %{name}-%{version}

%build
export GO111MODULE=on
export GOFLAGS=-mod=vendor

export LDFLAGS="-X \"github.com/sensu/sensu-go/version.Version=%{version}+oss_el%{epel}\" \
                -X \"github.com/sensu/sensu-go/version.BuildDate=`date +%Y-%m-%d`\""
for cmd in cmd/* ; do
  %gobuild -o _bin/$(basename $cmd) ./$cmd
done
rm -f _bin/loadit

%install
install -m 0755 -vd                     %{buildroot}%{_sbindir}
install -m 0755 -vp _bin/*              %{buildroot}%{_sbindir}/

install -m 0755 -vd                     %{buildroot}%{_tmpfilesdir}
install -m 0755 -vd                     %{buildroot}%{_unitdir}
install -m 0755 -vd                     %{buildroot}%{_sysconfdir}/sensu
install -m 0755 -vd                     %{buildroot}%{_sharedstatedir}/sensu
install -m 0755 -vd                     %{buildroot}%{_localstatedir}/cache/sensu
install -m 0755 -vd                     %{buildroot}%{_localstatedir}/log/sensu
install -m 0755 -vd                     %{buildroot}%{_rundir}/sensu
install -m 0755 -vd                     %{buildroot}%{_sysconfdir}/logrotate.d
install -pm 0644 %{SOURCE2}             %{buildroot}%{_unitdir}/sensu-backend.service
install -pm 0640 %{SOURCE4}             %{buildroot}%{_sysconfdir}/sensu/backend.yml
install -pm 0644 %{SOURCE3}             %{buildroot}%{_unitdir}/sensu-agent.service
install -pm 0640 %{SOURCE5}             %{buildroot}%{_sysconfdir}/sensu/agent.yml
install -pm 0644 %{SOURCE6}             %{buildroot}%{_tmpfilesdir}/%{name}.conf
install -pm 0644 %{SOURCE7}             %{buildroot}%{_sysconfdir}/logrotate.d/%{name}.conf

%pre backend
getent group sensu >/dev/null || groupadd -r sensu
getent passwd sensu >/dev/null || \
    useradd -r -g sensu -d %{_sharedstatedir}/sensu -s /sbin/nologin \
    -c "Sensu User" sensu
exit 0

%pre agent
getent group sensu >/dev/null || groupadd -r sensu
getent passwd sensu >/dev/null || \
    useradd -r -g sensu -d %{_sharedstatedir}/sensu -s /sbin/nologin \
    -c "Sensu User" sensu
exit 0

%post backend
%systemd_post sensu-backend.service

%post agent
%systemd_post sensu-agent.service

%preun backend
%systemd_preun sensu-backend.service

%preun agent
%systemd_preun sensu-agent.service

%postun backend
%systemd_postun sensu-backend.service

%postun agent
%systemd_postun sensu-agent.service


%files cli
%license LICENSE
%doc CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md FAQ.md README.md
%{_sbindir}/sensuctl

%files backend
%license LICENSE
%attr(-,sensu,sensu) %dir %{_sharedstatedir}/sensu/
%attr(755, sensu, sensu) %dir %{_sysconfdir}/sensu/
%attr(755, sensu, sensu) %dir %{_localstatedir}/cache/sensu/
%attr(755, sensu, sensu) %dir %{_localstatedir}/log/sensu/
%ghost %attr(755, sensu, sensu) %{_rundir}/sensu/
%config(noreplace) %attr(644, sensu, sensu) %{_sysconfdir}/sensu/backend.yml
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf
%{_unitdir}/sensu-backend.service
%{_sbindir}/sensu-backend
%{_tmpfilesdir}/%{name}.conf
%exclude %{_sysconfdir}/sensu/agent.yml

%files agent
%license LICENSE
%attr(-,sensu,sensu) %dir /var/lib/sensu/
%attr(755, sensu, sensu) %dir %{_sysconfdir}/sensu/
%attr(755, sensu, sensu) %dir %{_localstatedir}/cache/sensu/
%attr(755, sensu, sensu) %dir %{_localstatedir}/log/sensu/
%ghost %attr(755, sensu, sensu) %{_rundir}/sensu/
%config(noreplace) %attr(644, sensu, sensu) %{_sysconfdir}/sensu/agent.yml
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}.conf
%{_unitdir}/sensu-agent.service
%{_sbindir}/sensu-agent
%{_tmpfilesdir}/%{name}.conf
%exclude %{_sysconfdir}/sensu/backend.yml

%changelog
* Wed Apr 01 2020 Devin Acosta <devin> - 5.21.0-3
- Fixed Configs being overwritten, added +oss_el7|8 to version

* Sun Mar 29 2020 Devin Acosta <devin> - 5.21.0-2
- Added SPEC to create sensu-go-backend/sensu-go-agent RPMS

* Sun Mar 29 2020 Devin Acosta <devin> - 5.21.0-1
- Initial package

=====================================================================================================

SRPMs: https://eclipseo.fedorapeople.org/sensu-go/

Please see if this works for you and if you'd be able to take ownership and maintain the SPECs.

Comment 8 Package Review 2021-06-24 00:45:23 UTC
This is an automatic check from review-stats script.

This review request ticket hasn't been updated for some time, but it seems
that the review is still being working out by you. If this is right, please
respond to this comment clearing the NEEDINFO flag and try to reach out the
submitter to proceed with the review.

If you're not interested in reviewing this ticket anymore, please clear the
fedora-review flag and reset the assignee, so that a new reviewer can take
this ticket.

Without any reply, this request will shortly be resetted.


Note You need to log in before you can comment on or make changes to this bug.