woblerr commented on code in PR #87:
URL: https://github.com/apache/cloudberry-backup/pull/87#discussion_r3140308563


##########
gpbackup_exporter.go:
##########
@@ -0,0 +1,172 @@
+//go:build gpbackup_exporter
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+
+package main
+
+import (
+       "log/slog"
+       "os"
+       "os/signal"
+       "path/filepath"
+       "strings"
+       "syscall"
+       "time"
+
+       "github.com/alecthomas/kingpin/v2"
+       "github.com/apache/cloudberry-backup/exporter"
+       "github.com/prometheus/client_golang/prometheus"
+       version_collector 
"github.com/prometheus/client_golang/prometheus/collectors/version"
+       "github.com/prometheus/common/promslog"
+       "github.com/prometheus/common/promslog/flag"
+       "github.com/prometheus/common/version"
+       "github.com/prometheus/exporter-toolkit/web/kingpinflag"
+)
+
+const exporterName = "gpbackup_exporter"
+
+func main() {
+       var (
+               webPath = kingpin.Flag(
+                       "web.telemetry-path",
+                       "Path under which to expose metrics.",
+               ).Default("/metrics").String()
+               webAdditionalToolkitFlags = 
kingpinflag.AddFlags(kingpin.CommandLine, ":19854")
+               collectionInterval        = kingpin.Flag(
+                       "collect.interval",
+                       "Collecting metrics interval in seconds.",
+               ).Default("600").Int()
+               collectionDepth = kingpin.Flag(
+                       "collect.depth",
+                       "Metrics depth collection in days. Metrics for backup 
older than this interval will not be collected. 0 - disable.",
+               ).Default("0").Int()
+               gpbckpHistoryFilePath = kingpin.Flag(
+                       "gpbackup.history-file",
+                       "Path to gpbackup_history.db.",
+               ).Default("").String()
+               gpbckpIncludeDB = kingpin.Flag(
+                       "gpbackup.db-include",
+                       "Specific db for collecting metrics. Can be specified 
several times.",
+               ).Default("").PlaceHolder("\"\"").Strings()
+               gpbckpExcludeDB = kingpin.Flag(
+                       "gpbackup.db-exclude",
+                       "Specific db to exclude from collecting metrics. Can be 
specified several times.",
+               ).Default("").PlaceHolder("\"\"").Strings()
+               gpbckpBackupType = kingpin.Flag(
+                       "gpbackup.backup-type",
+                       "Specific backup type for collecting metrics. One of: 
[full, incremental, data-only, metadata-only].",
+               ).Default("").String()
+               gpbckpBackupCollectDeleted = kingpin.Flag(
+                       "gpbackup.collect-deleted",
+                       "Collecting metrics for deleted backups.",
+               ).Default("false").Bool()
+               gpbckpBackupCollectFailed = kingpin.Flag(
+                       "gpbackup.collect-failed",
+                       "Collecting metrics for failed backups.",
+               ).Default("false").Bool()
+       )
+       // Set logger config.
+       promslogConfig := &promslog.Config{}
+       // Add flags log.level and log.format from promslog package.
+       flag.AddFlags(kingpin.CommandLine, promslogConfig)
+       kingpin.Version(version.Print(exporterName))
+       // Add short help flag.
+       kingpin.HelpFlag.Short('h')
+       // Load command line arguments.
+       kingpin.Parse()
+       // Setup signal catching.
+       sigs := make(chan os.Signal, 1)
+       // Catch listed signals.
+       signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
+       // Set logger.
+       logger := promslog.New(promslogConfig)
+       // Method invoked upon seeing signal.
+       go func(logger *slog.Logger) {
+               s := <-sigs
+               logger.Warn(
+                       "Stopping exporter",
+                       "name", filepath.Base(os.Args[0]),
+                       "signal", s)
+               os.Exit(1)

Review Comment:
   yes, os.Exit(0)  looks better, fixed in 
https://github.com/apache/cloudberry-backup/pull/87/commits/21d0b83647189f16ff44eedb7d2eac64e8ce20c7



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to