Compare commits

..

No commits in common. "554278772d06c2c723b462f4ea7f2ff8d683559a" and "42ba7d7490d5b8ef7fd10c53504b0c3476c67e24" have entirely different histories.

7 changed files with 0 additions and 255 deletions

View File

@ -1,85 +0,0 @@
From 92c8d1e028bc6a102bb578e03ba19776bff379ed Mon Sep 17 00:00:00 2001
From: marie <marie.payne@hotmail.ca>
Date: Thu, 7 Oct 2021 06:10:11 -0400
Subject: [PATCH] Log shutdown gracefully (#428)
Log graceful shutdown at info level only
reference:
https://github.com/prometheus/pushgateway/commit/92c8d1e028bc6a102bb578e03ba19776bff379ed
Signed-off-by: mjip <marie.payne@hotmail.ca>
---
main.go | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/main.go b/main.go
index bdf61e8..2927d71 100644
--- a/main.go
+++ b/main.go
@@ -14,6 +14,7 @@
package main
import (
+ "context"
"fmt"
"net"
"net/http"
@@ -25,7 +26,6 @@ import (
"path/filepath"
"strings"
"syscall"
- "time"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
@@ -191,13 +191,20 @@ func main() {
mux.Handle(apiPath+"/v1/", http.StripPrefix(apiPath+"/v1", av1))
- go closeListenerOnQuit(l, quitCh, logger)
- err = (&http.Server{Addr: *listenAddress, Handler: mux}).Serve(l)
- level.Error(logger).Log("msg", "HTTP server stopped", "err", err)
- // To give running connections a chance to submit their payload, we wait
- // for 1sec, but we don't want to wait long (e.g. until all connections
- // are done) to not delay the shutdown.
- time.Sleep(time.Second)
+ server := &http.Server{
+ Addr: *listenAddress,
+ Handler: mux,
+ }
+ go shutdownServerOnQuit(server, quitCh, logger)
+ err = (server).Serve(l)
+
+ // In the case of a graceful shutdown, do not log the error.
+ if err == http.ErrServerClosed {
+ level.Info(logger).Log("msg", "HTTP server stopped")
+ } else {
+ level.Error(logger).Log("msg", "HTTP server stopped", "err", err)
+ }
+
if err := ms.Shutdown(); err != nil {
level.Error(logger).Log("msg", "problem shutting down metric storage", "err", err)
}
@@ -237,9 +244,9 @@ func computeRoutePrefix(prefix string, externalURL *url.URL) string {
return prefix
}
-// closeListenerOnQuite closes the provided listener upon closing the provided
+// shutdownServerOnQuit shutdowns the provided server upon closing the provided
// quitCh or upon receiving a SIGINT or SIGTERM.
-func closeListenerOnQuit(l net.Listener, quitCh <-chan struct{}, logger log.Logger) {
+func shutdownServerOnQuit(server *http.Server, quitCh <-chan struct{}, logger log.Logger) error {
notifier := make(chan os.Signal, 1)
signal.Notify(notifier, os.Interrupt, syscall.SIGTERM)
@@ -251,5 +258,5 @@ func closeListenerOnQuit(l net.Listener, quitCh <-chan struct{}, logger log.Logg
level.Warn(logger).Log("msg", "received termination request via web service, exiting gracefully...")
break
}
- l.Close()
+ return server.Shutdown(context.Background())
}
--
2.30.0

View File

@ -1,65 +0,0 @@
From f4984952bc9259a34b93b4bdf7581c1e586e7b36 Mon Sep 17 00:00:00 2001
From: bzg1107 <preloyalwhite@163.com>
Date: Sat, 31 Jul 2021 16:36:48 +0800
Subject: [PATCH] fix promu dependence and fix not found web
---
Makefile.common | 10 ++++++----
main.go | 5 +----
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/Makefile.common b/Makefile.common
index ce80d53..d33966d 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -261,11 +261,13 @@ common-docker-manifest:
promu: $(PROMU)
$(PROMU):
- $(eval PROMU_TMP := $(shell mktemp -d))
- curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
+# $(eval PROMU_TMP := $(shell mktemp -d))
+# curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
+# mkdir -p $(FIRST_GOPATH)/bin
+# cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
+# rm -r $(PROMU_TMP)
mkdir -p $(FIRST_GOPATH)/bin
- cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
- rm -r $(PROMU_TMP)
+ cp /usr/bin/promu $(FIRST_GOPATH)/bin/promu
.PHONY: proto
proto:
diff --git a/main.go b/main.go
index 0c47d9d..bdf61e8 100644
--- a/main.go
+++ b/main.go
@@ -34,8 +34,6 @@ import (
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/route"
"github.com/prometheus/common/version"
- "github.com/prometheus/exporter-toolkit/web"
- webflag "github.com/prometheus/exporter-toolkit/web/kingpinflag"
"gopkg.in/alecthomas/kingpin.v2"
dto "github.com/prometheus/client_model/go"
@@ -61,7 +59,6 @@ func (lf logFunc) Println(v ...interface{}) {
func main() {
var (
app = kingpin.New(filepath.Base(os.Args[0]), "The Pushgateway")
- webConfig = webflag.AddFlags(app)
listenAddress = app.Flag("web.listen-address", "Address to listen on for the web interface, API, and telemetry.").Default(":9091").String()
metricsPath = app.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
externalURL = app.Flag("web.external-url", "The URL under which the Pushgateway is externally reachable.").Default("").URL()
@@ -195,7 +192,7 @@ func main() {
mux.Handle(apiPath+"/v1/", http.StripPrefix(apiPath+"/v1", av1))
go closeListenerOnQuit(l, quitCh, logger)
- err = web.Serve(l, &http.Server{Addr: *listenAddress, Handler: mux}, *webConfig, logger)
+ err = (&http.Server{Addr: *listenAddress, Handler: mux}).Serve(l)
level.Error(logger).Log("msg", "HTTP server stopped", "err", err)
// To give running connections a chance to submit their payload, we wait
// for 1sec, but we don't want to wait long (e.g. until all connections
--
2.30.0

Binary file not shown.

View File

@ -1 +0,0 @@
PUSHGATEWAY_OPTS='--web.listen-address=0.0.0.0:9091'

View File

@ -1,18 +0,0 @@
# -*- mode: conf -*-
[Unit]
Description=Prometheus pushgateway.
Documentation=https://github.com/prometheus/pushgateway
After=network.target
[Service]
EnvironmentFile=-/etc/default/pushgateway
User=prometheus
ExecStart=/usr/bin/pushgateway \
$PUSHGATEWAY_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target

View File

@ -1,86 +0,0 @@
%define debug_package %{nil}
%ifarch aarch64
%global hostarch arm64
%endif
%ifarch x86_64
%global hostarch amd64
%endif
Name: pushgateway
Version: 1.4.1
Release: 5
Summary: Prometheus pushgateway.
License: ASL 2.0
URL: https://github.com/prometheus/%{name}
Source0: https://github.com/prometheus/%{name}/archive/v%{version}/%{name}-%{version}.tar.gz
Source1: %{name}.service
Source2: %{name}.default
Source3: vendor.tar.gz
Patch0: 0001-fix-promu-dependence-and-fix-not-found-web.patch
Patch1: 0001-Log-shutdown-gracefully-428.patch
BuildRequires: golang >= 1.13
BuildRequires: promu
BuildRequires: systemd
%{?systemd_requires}
Requires(pre): shadow-utils
%description
The Prometheus Pushgateway exists to allow ephemeral and batch jobs to expose their metrics to Prometheus.
Since these kinds of jobs may not exist long enough to be scraped, they can instead push their metrics to a Pushgateway.
The Pushgateway then exposes these metrics to Prometheus.
%prep
%autosetup -p1 -n %{name}-%{version}
%setup -T -D -a 3 -n %{name}-%{version}
%build
mkdir -p $(pwd)/bin
export GOBIN=$(pwd)/bin
go build -mod=vendor -buildmode=pie -ldflags "-s -w -linkmode=external -extldflags '-Wl,-z,relro -Wl,-z,now' " -o bin ./ ...
%install
mkdir -p %{buildroot}%{_bindir}
install -D -m 755 bin/%{name} %{buildroot}%{_bindir}/
mkdir -vp %{buildroot}%{_sharedstatedir}/prometheus
install -D -m 644 %{SOURCE1} %{buildroot}%{_unitdir}/%{name}.service
install -D -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/default/%{name}
%pre
getent group prometheus >/dev/null || groupadd -r prometheus
getent passwd prometheus >/dev/null || \
useradd -r -g prometheus -d %{_sharedstatedir}/prometheus -s /sbin/nologin \
-c "Prometheus services" prometheus
exit 0
%post
%systemd_post %{name}.service
%preun
%systemd_preun %{name}.service
%postun
%systemd_postun %{name}.service
%files
%defattr(-,root,root,-)
%{_bindir}/*
%{_unitdir}/%{name}.service
%config(noreplace) %{_sysconfdir}/default/%{name}
%dir %attr(755, prometheus, prometheus)%{_sharedstatedir}/prometheus
%changelog
* Thu Feb 09 2023 xu_ping <xuping33@h-partners.com> - 1.4.1-5
- set flags for BIND_NOW
* Thu Feb 09 2023 xu_ping <xuping33@h-partners.com> - 1.4.1-4
- set flags for build
* Thu Jan 5 2023 caodongxia <caodongxia@h-partners.com> - 1.4.1-3
- Add buildRequires systemd
* Mon Oct 11 2021 chenchen <chen_aka_jan@163.com> - 1.4.1-2
- Logr shutdownr gracefully(#428
* Wed Jul 14 2021 baizhonggui <baizhonggui@huawei.com> - 1.4.1-1
- Package init

Binary file not shown.