Skip to content

Commit

Permalink
feat: adding run_plugins_if_no_data to handle plugin calls when templ…
Browse files Browse the repository at this point in the history
…ate has no records
  • Loading branch information
Hardikl committed Jul 8, 2024
1 parent 52b4ae7 commit b1bcc9f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Rest struct {
Prop *prop
endpoints []*endPoint
isIgnoreUnknownFieldsEnabled bool
RunPluginsIfNoData bool
}

type endPoint struct {
Expand Down Expand Up @@ -192,6 +193,12 @@ func (r *Rest) InitVars(config *node.Node) {
} else {
r.Logger.Info().Str("timeout", rest.DefaultTimeout).Msg("Using default timeout")
}

// if the object template includes a run_plugins_if_no_data, then honour that
r.RunPluginsIfNoData = false
if r.Params.HasChildS("run_plugins_if_no_data") {
r.RunPluginsIfNoData = true
}
}

func (r *Rest) InitClient() error {
Expand Down Expand Up @@ -399,7 +406,7 @@ func (r *Rest) PollData() (map[string]*matrix.Matrix, error) {
}

if len(records) == 0 {
if r.Object == "Qtree" {
if r.RunPluginsIfNoData {
return r.Matrix, errs.New(errs.ErrNoInstance, "no "+r.Object+" instances on cluster")
}
return nil, errs.New(errs.ErrNoInstance, "no "+r.Object+" instances on cluster")
Expand Down
9 changes: 8 additions & 1 deletion cmd/collectors/zapi/collector/zapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Zapi struct {
instanceKeyPaths [][]string
instanceLabelPaths map[string]string
shortestPathPrefix []string
RunPluginsIfNoData bool
}

func init() {
Expand Down Expand Up @@ -147,6 +148,12 @@ func (z *Zapi) InitVars() error {
if timeout := z.Params.GetChildContentS("client_timeout"); timeout != "" {
z.Client.SetTimeout(timeout)
}

// if the object template includes a run_plugins_if_no_data, then honour that
z.RunPluginsIfNoData = false
if z.Params.HasChildS("run_plugins_if_no_data") {
z.RunPluginsIfNoData = true
}
return nil
}

Expand Down Expand Up @@ -405,7 +412,7 @@ func (z *Zapi) PollData() (map[string]*matrix.Matrix, error) {
z.AddCollectCount(count)

if numInstances == 0 {
if z.Object == "Qtree" {
if z.RunPluginsIfNoData {
return z.Matrix, errs.New(errs.ErrNoInstance, "")
}
return nil, errs.New(errs.ErrNoInstance, "")
Expand Down
3 changes: 3 additions & 0 deletions conf/rest/9.12.0/qtree.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ endpoints:
- ^status => status
- filter:
- qtree=!""

run_plugins_if_no_data: true

plugins:
- Qtree:
quotaType:
Expand Down
1 change: 1 addition & 0 deletions conf/zapi/cdot/9.8.0/qtree.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ counters:
- ^status

collect_only_labels: true
run_plugins_if_no_data: true

plugins:
- LabelAgent:
Expand Down

0 comments on commit b1bcc9f

Please sign in to comment.