Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
disable vhosts api if no vhosts defined (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Feb 26, 2023
1 parent a6ac298 commit 41855cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
8 changes: 6 additions & 2 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ func (a *Agent) run(ctx context.Context) {
if len(a.VnodesConfDir) > 0 {
a.Infof("looking for 'vnodes/' in %v", a.VnodesConfDir)
if s, _ := a.VnodesConfDir.Find("vnodes/"); s != "" {
a.Infof("found '%s'", s)
builder.VNodeRegistry = vnode.NewRegistry(s)
reg := vnode.NewRegistry(s)
a.Infof("found '%s' (%d vhosts)", s, reg.Len())
if reg.Len() == 0 {
vnode.Disabled = true
}
builder.VNodeRegistry = reg
}
}

Expand Down
6 changes: 6 additions & 0 deletions agent/job/vnode/vnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"gopkg.in/yaml.v2"
)

var Disabled = false // TODO: remove after Netdata v1.39.0. Fix for "from source" stable-channel installations.

func NewRegistry(confDir string) *Registry {
r := &Registry{
confDir: confDir,
Expand All @@ -37,6 +39,10 @@ type Registry struct {
*logger.Logger
}

func (r *Registry) Len() int {
return len(r.nodes)
}

func (r *Registry) Lookup(key string) (*VirtualNode, bool) {
v, ok := r.nodes[key]
return v, ok
Expand Down
18 changes: 13 additions & 5 deletions agent/module/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync"
"time"

"github.com/netdata/go.d.plugin/agent/job/vnode"
"github.com/netdata/go.d.plugin/agent/netdataapi"
"github.com/netdata/go.d.plugin/logger"
)
Expand Down Expand Up @@ -263,6 +264,10 @@ func (j *Job) Cleanup() {
return
}

if !vnode.Disabled {
_ = j.api.HOST(j.vnodeGUID)
}

if j.runChart.created {
j.runChart.MarkRemove()
j.createChart(j.runChart)
Expand All @@ -275,6 +280,7 @@ func (j *Job) Cleanup() {
}
}
}

if j.buf.Len() > 0 {
writeLock.Lock()
_, _ = io.Copy(j.out, j.buf)
Expand Down Expand Up @@ -353,12 +359,14 @@ func (j *Job) collect() (result map[string]int64) {
}

func (j *Job) processMetrics(metrics map[string]int64, startTime time.Time, sinceLastRun int) bool {
if !j.vnodeCreated && j.vnodeGUID != "" {
_ = j.api.HOSTINFO(j.vnodeGUID, j.vnodeHostname, j.vnodeLabels)
j.vnodeCreated = true
}
if !vnode.Disabled {
if !j.vnodeCreated && j.vnodeGUID != "" {
_ = j.api.HOSTINFO(j.vnodeGUID, j.vnodeHostname, j.vnodeLabels)
j.vnodeCreated = true
}

_ = j.api.HOST(j.vnodeGUID)
_ = j.api.HOST(j.vnodeGUID)
}

if !ndInternalMonitoringDisabled && !j.runChart.created {
j.runChart.ID = fmt.Sprintf("execution_time_of_%s", j.FullName())
Expand Down

0 comments on commit 41855cd

Please sign in to comment.