Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Add flag to disable annotation discovery #82

Merged
merged 2 commits into from
Dec 17, 2020

Conversation

JSchuenke
Copy link
Contributor

  • Move discovery of endpoints from resources to new endpointCreator
  • Add unit tests for new endpointCreator
  • Add documentation about new config value disable_annotation_discovery

MONIT-21378

- Move discovery of endpoints from resources to new endpointCreator
- Add unit tests for new endpointCreator
- Add documentation about new config value disable_annotation_discovery

[MONIT-21378](https://wavefront.atlassian.net/browse/MONIT-21378)
@JSchuenke JSchuenke force-pushed the MONIT-21378-disable-annotation-discovery branch from db2aef4 to b12b7bb Compare December 17, 2020 22:38
Containers: make([]v1.Container, 0),
}

got := e.discoverEndpoints(resource)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why this discovers when the resource does not have any annotations on it (under the meta section)?

Copy link
Contributor Author

@JSchuenke JSchuenke Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works because down in the encoder it assumes that we're using an annotation and then fills in all the default values when nothing is defined in meta:

func Param(meta metav1.ObjectMeta, annotation, cfgVal, defaultVal string) string {
	value := ""
	// give precedence to annotation
	if annotation != "" {
		value = meta.GetAnnotations()[annotation]
	}
	if value == "" {
		// then config
		value = cfgVal
	}
	if value == "" {
		// then default
		value = defaultVal
	}
	return value
}

func (e *endpointCreator) discoverEndpointsWithAnnotations(resource discovery.Resource) []*discovery.Endpoint {
var eps []*discovery.Endpoint
// delegate to runtime handlers if no matching delegate
if ep := e.makeEndpoint(resource, discovery.PluginConfig{Type: "prometheus", Name: "example"}); ep != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably remove the example name (just leave the name empty) since that is used to determine whether to check for annotations here:

if rule.Name == "" && scrape != "true" {

Kind: discovery.PodType.String(),
IP: "0.0.0.0",
Meta: metav1.ObjectMeta{},
Containers: make([]v1.Container, 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This resource needs an annotation on it for it to validly get skipped

plugins/discovery/endpoint_creator_test.go Show resolved Hide resolved
@vikramraman vikramraman merged commit 32bd340 into master Dec 17, 2020
@JSchuenke JSchuenke deleted the MONIT-21378-disable-annotation-discovery branch December 17, 2020 23:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants