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

Add Prometheus scrape annotations to agent #684

Merged
merged 1 commit into from
Oct 8, 2019
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
12 changes: 12 additions & 0 deletions pkg/inject/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ var (
Label = "sidecar.jaegertracing.io/injected"
// AnnotationLegacy holds the annotation name we had in the past, which we keep for backwards compatibility
AnnotationLegacy = "inject-jaeger-agent"
// PrometheusDefaultAnnotations is a map containing annotations for prometheus to be inserted at sidecar in case it doesn't have any
PrometheusDefaultAnnotations = map[string]string{
"prometheus.io/scrape": "true",
"prometheus.io/port": "5778",
}
)

const (
Expand Down Expand Up @@ -210,6 +215,13 @@ func decorate(dep *appsv1.Deployment) {
}
}
}
for key, value := range PrometheusDefaultAnnotations {
_, ok := dep.Annotations[key]
if !ok {
dep.Annotations[key] = value
}
}

}

func hasEnv(name string, vars []corev1.EnvVar) bool {
Expand Down
30 changes: 30 additions & 0 deletions pkg/inject/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,36 @@ func TestSidecarWithLabel(t *testing.T) {
assert.Equal(t, dep2.Labels[Label], jaeger.Name)
}

func TestSidecarWithoutPrometheusAnnotations(t *testing.T) {
// prepare
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestSidecarWithoutPrometheusAnnotations"})
dep := Sidecar(jaeger, dep(map[string]string{Annotation: jaeger.Name}, map[string]string{}))

// test
dep = Sidecar(jaeger, dep)

// verify
assert.Contains(t, dep.Annotations, "prometheus.io/scrape")
assert.Contains(t, dep.Annotations, "prometheus.io/port")
}

func TestSidecarWithPrometheusAnnotations(t *testing.T) {
// prepare
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestSidecarWithPrometheusAnnotations"})
dep := dep(map[string]string{
Annotation: jaeger.Name,
"prometheus.io/scrape": "false",
"prometheus.io/port": "9090",
}, map[string]string{})

// test
dep = Sidecar(jaeger, dep)

// verify
assert.Equal(t, dep.Annotations["prometheus.io/scrape"], "false")
assert.Equal(t, dep.Annotations["prometheus.io/port"], "9090")
}

func dep(annotations map[string]string, labels map[string]string) *appsv1.Deployment {
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down