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

feat: support zapi like prefixing object #786

Merged
merged 2 commits into from
Jan 18, 2022
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
23 changes: 19 additions & 4 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type endPoint struct {
}

type prop struct {
object string
query string
instanceKeys []string
instanceLabels map[string]string
Expand Down Expand Up @@ -84,18 +85,32 @@ func (r *Rest) Init(a *collector.AbstractCollector) error {
return err
}

r.Logger.Info().Str("cluster", r.client.Cluster().Name).Msgf("connected to %s", r.client.Cluster().Info)

r.Matrix.SetGlobalLabel("cluster", r.client.Cluster().Name)

if err = r.initCache(); err != nil {
return err
}

if err = r.InitMatrix(); err != nil {
return err
}
r.Logger.Info().Msgf("initialized cache with %d metrics", len(r.Matrix.GetMetrics()))

return nil
}

func (r *Rest) InitMatrix() error {
// overwrite from abstract collector
r.Matrix.Object = r.prop.object
// Add system (cluster) name
r.Matrix.SetGlobalLabel("cluster", r.client.Cluster().Name)
if r.Params.HasChildS("labels") {
for _, l := range r.Params.GetChildS("labels").GetChildren() {
r.Matrix.SetGlobalLabel(l.GetNameS(), l.GetContentS())
}
}

return nil
}

func (r *Rest) getClient(a *collector.AbstractCollector, config *node.Node) (*rest.Client, error) {
var (
poller *conf.Poller
Expand Down
10 changes: 4 additions & 6 deletions cmd/collectors/rest/templating.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ func (r *Rest) initCache() error {
display, name, kind string
)

if r.Object == "" {
if x := r.Params.GetChildContentS("object"); x != "" {
r.Object = x
}
if x := r.Params.GetChildContentS("object"); x != "" {
r.prop.object = x
} else {
r.prop.object = strings.ToLower(r.Object)
}

r.Matrix.Object = strings.ToLower(r.Object)

if e := r.Params.GetChildS("export_options"); e != nil {
r.Matrix.SetExportOptions(e)
}
Expand Down