Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make error handling inside Collect cycles more consistent #33

Merged
merged 2 commits into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions collector/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"github.com/SUSE/sap_host_exporter/internal/sapcontrol"
)

func NewCollector(webService sapcontrol.WebService) (*dispatcherCollector, error) {
func NewCollector(webService sapcontrol.WebService) (*alertCollector, error) {

c := &dispatcherCollector{
c := &alertCollector{
collector.NewDefaultCollector("alert"),
webService,
}
Expand All @@ -23,12 +23,12 @@ func NewCollector(webService sapcontrol.WebService) (*dispatcherCollector, error
return c, nil
}

type dispatcherCollector struct {
type alertCollector struct {
collector.DefaultCollector
webService sapcontrol.WebService
}

func (c *dispatcherCollector) Collect(ch chan<- prometheus.Metric) {
func (c *alertCollector) Collect(ch chan<- prometheus.Metric) {
log.Debugln("Collecting Alert metrics")

var err error
Expand All @@ -40,13 +40,12 @@ func (c *dispatcherCollector) Collect(ch chan<- prometheus.Metric) {
}, ch)

if err != nil {
log.Warnf("Some metrics could not be recorded: %s", err)
log.Warnf("Alert Collector scrape failed: %s", err)
}
}

func (c *dispatcherCollector) recordHAConfigChecks(ch chan<- prometheus.Metric) error {
func (c *alertCollector) recordHAConfigChecks(ch chan<- prometheus.Metric) error {
response, err := c.webService.HACheckConfig()

if err != nil {
return errors.Wrap(err, "SAPControl web service error")
}
Expand All @@ -59,7 +58,7 @@ func (c *dispatcherCollector) recordHAConfigChecks(ch chan<- prometheus.Metric)
return nil
}

func (c *dispatcherCollector) recordHAFailoverConfigChecks(ch chan<- prometheus.Metric) error {
func (c *alertCollector) recordHAFailoverConfigChecks(ch chan<- prometheus.Metric) error {
response, err := c.webService.HACheckFailoverConfig()

if err != nil {
Expand All @@ -68,13 +67,13 @@ func (c *dispatcherCollector) recordHAFailoverConfigChecks(ch chan<- prometheus.

err = c.recordHAChecks(response.Checks, ch)
if err != nil {
return errors.Wrap(err, "Could not record HACheck")
return errors.Wrap(err, "could not record HACheck")
}

return nil
}

func (c *dispatcherCollector) recordHAChecks(checks []*sapcontrol.HACheck, ch chan<- prometheus.Metric) error {
func (c *alertCollector) recordHAChecks(checks []*sapcontrol.HACheck, ch chan<- prometheus.Metric) error {
for _, check := range checks {
err := c.recordHACheck(check, ch)
if err != nil {
Expand All @@ -84,18 +83,18 @@ func (c *dispatcherCollector) recordHAChecks(checks []*sapcontrol.HACheck, ch ch
return nil
}

func (c *dispatcherCollector) recordHACheck(check *sapcontrol.HACheck, ch chan<- prometheus.Metric) error {
func (c *alertCollector) recordHACheck(check *sapcontrol.HACheck, ch chan<- prometheus.Metric) error {
stateCode, err := sapcontrol.HaVerificationStateToFloat(check.State)
category, err := sapcontrol.HaCheckCategoryToString(check.Category)
if err != nil {
return errors.Wrapf(err, "Unable to process SAPControl HACheck data: %v", *check)
return errors.Wrapf(err, "unable to process SAPControl HACheck data: %v", *check)
}
ch <- c.MakeGaugeMetric("ha_check", stateCode, check.Description, category, check.Comment)

return nil
}

func (c *dispatcherCollector) recordHAFailoverActive(ch chan<- prometheus.Metric) error {
func (c *alertCollector) recordHAFailoverActive(ch chan<- prometheus.Metric) error {
response, err := c.webService.HAGetFailoverConfig()

if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions collector/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dispatcher

import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -33,15 +34,18 @@ type dispatcherCollector struct {
func (c *dispatcherCollector) Collect(ch chan<- prometheus.Metric) {
log.Debugln("Collecting Dispatcher metrics")

c.recordWorkProcessQueueStats(ch)
err := c.recordWorkProcessQueueStats(ch)
if err != nil {
log.Warnf("Dispatcher Collector scrape failed: %s", err)
return
}
}

func (c *dispatcherCollector) recordWorkProcessQueueStats(ch chan<- prometheus.Metric) {
func (c *dispatcherCollector) recordWorkProcessQueueStats(ch chan<- prometheus.Metric) error {
queueStatistic, err := c.webService.GetQueueStatistic()

if err != nil {
log.Warnf("SAPControl web service error: %s", err)
return
return errors.Wrap(err, "SAPControl web service error")
}

// for each work queue, we record a different line for each stat of that queue, with the type as a common label
Expand All @@ -52,4 +56,6 @@ func (c *dispatcherCollector) recordWorkProcessQueueStats(ch chan<- prometheus.M
ch <- c.MakeCounterMetric("queue_writes", float64(queue.Writes), queue.Type)
ch <- c.MakeCounterMetric("queue_reads", float64(queue.Reads), queue.Type)
}

return nil
}
14 changes: 9 additions & 5 deletions collector/enqueue_server/enqueue_server.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package enqueue_server

import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -55,15 +56,16 @@ type enqueueServerCollector struct {
func (c *enqueueServerCollector) Collect(ch chan<- prometheus.Metric) {
log.Debugln("Collecting Enqueue Server metrics")

c.recordEnqStats(ch)
err := c.recordEnqStats(ch)
if err != nil {
log.Warnf("Enqueue Server Collector scrape failed: %s", err)
}
}

func (c *enqueueServerCollector) recordEnqStats(ch chan<- prometheus.Metric) {
func (c *enqueueServerCollector) recordEnqStats(ch chan<- prometheus.Metric) error {
enqStatistic, err := c.webService.EnqGetStatistic()

if err != nil {
log.Warnf("SAPControl web service error: %s", err)
return
return errors.Wrap(err, "SAPControl web service error")
}

ch <- c.MakeGaugeMetric("owner_now", float64(enqStatistic.OwnerNow))
Expand Down Expand Up @@ -123,4 +125,6 @@ func (c *enqueueServerCollector) recordEnqStats(ch chan<- prometheus.Metric) {
} else {
ch <- c.MakeGaugeMetric("replication_state", replicationState)
}

return nil
}
4 changes: 2 additions & 2 deletions collector/start_service/start_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (c *startServiceCollector) Collect(ch chan<- prometheus.Metric) {

err := c.recordProcesses(ch)
if err != nil {
log.Warnf("Some metrics could not be recorded: %s", err)
log.Warnf("Start Service Collector scrape failed: %s", err)
return
}
}
Expand All @@ -49,7 +49,7 @@ func (c *startServiceCollector) recordProcesses(ch chan<- prometheus.Metric) err
for _, process := range processList.Processes {
state, err := sapcontrol.StateColorToFloat(process.Dispstatus)
if err != nil {
return errors.Wrapf(err, "Unable to process SAPControl OSProcess data: %v", *process)
return errors.Wrapf(err, "unable to process SAPControl OSProcess data: %v", *process)
}
ch <- c.MakeGaugeMetric("processes", state, process.Name, strconv.Itoa(int(process.Pid)), process.Textstatus)
}
Expand Down