Skip to content

Commit

Permalink
Adds isPipelineHealthy function
Browse files Browse the repository at this point in the history
  • Loading branch information
excalq authored and kuskoman committed Apr 27, 2023
1 parent f7c7c13 commit d8a42f9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions collectors/nodestats/pipeline_subcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
// pipelines of a logstash node.
// The collector is created once for each pipeline of the node.
type PipelineSubcollector struct {
Up *prometheus.Desc
EventsOut *prometheus.Desc
EventsFiltered *prometheus.Desc
EventsIn *prometheus.Desc
Expand All @@ -40,6 +41,7 @@ type PipelineSubcollector struct {
func NewPipelineSubcollector() *PipelineSubcollector {
descHelper := prometheus_helper.SimpleDescHelper{Namespace: namespace, Subsystem: fmt.Sprintf("%s_pipeline", subsystem)}
return &PipelineSubcollector{
Up: descHelper.NewDescWithHelpAndLabels("up", "Whether the pipeline is up or not.", "pipeline"),
EventsOut: descHelper.NewDescWithHelpAndLabels("events_out", "Number of events that have been processed by this pipeline.", "pipeline"),
EventsFiltered: descHelper.NewDescWithHelpAndLabels("events_filtered", "Number of events that have been filtered out by this pipeline.", "pipeline"),
EventsIn: descHelper.NewDescWithHelpAndLabels("events_in", "Number of events that have been inputted into this pipeline.", "pipeline"),
Expand Down Expand Up @@ -129,6 +131,24 @@ func (collector *PipelineSubcollector) Collect(pipeStats *responses.SinglePipeli
log.Printf("collected pipeline stats for pipeline %s in %s", pipelineID, collectingEnd.Sub(collectingStart))
}

func (collector *PipelineSubcollector) isPipelineHealthy(pipeReloadStats responses.PipelineReloadResponse) float64 {
// 1. If both timestamps are nil, the pipeline is healthy
if pipeReloadStats.LastSuccessTimestamp == nil && pipeReloadStats.LastFailureTimestamp == nil {
return 1
// 2. If last_failure_timestamp is set and last success timestamp is nil, the pipeline is unhealthy
} else if pipeReloadStats.LastFailureTimestamp != nil && pipeReloadStats.LastSuccessTimestamp == nil {
return 0
// 3. If last_success_timestamp < last_failure_timestamp, the pipeline is unhealthy
} else if pipeReloadStats.LastSuccessTimestamp.Before(*pipeReloadStats.LastFailureTimestamp) {
return 0
// 4. If last_success_timestamp > last_failure_timestamp, the pipeline is healthy
} else if pipeReloadStats.LastSuccessTimestamp.After(*pipeReloadStats.LastFailureTimestamp) {
return 1
}
// Missing field, likely due to version incompatibility - lacking information, assume healthy
return 1
}

// Plugins have non-unique names, so use both name and id as labels
// By default ids are a 36-char UUID, optionally prefixed the a plugin type, or a 64-char SHA256 hash
// If the id is set by the user, keep it. If it's a UUID, truncate it to the last 8 chars (1% chance of collision per 9291)
Expand Down

0 comments on commit d8a42f9

Please sign in to comment.