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

Fjernet spec.prometheus.enabled #135

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 0 additions & 2 deletions config/nais.io_applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ spec:
type: string
prometheus:
properties:
enabled:
type: boolean
path:
type: string
port:
Expand Down
1 change: 0 additions & 1 deletion pkg/apis/nais.io/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ type Probe struct {
}

type PrometheusConfig struct {
Enabled bool `json:"enabled,omitempty"`
Port string `json:"port,omitempty"`
Path string `json:"path,omitempty"`
}
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/nais.io/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ func getAppDefaults() *Application {
Strategy: Strategy{
Type: DeploymentStrategyRollingUpdate,
},
Prometheus: PrometheusConfig{
Path: "/metrics",
},
Ingresses: []string{},
Resources: ResourceRequirements{
Limits: ResourceSpec{
Expand Down
18 changes: 10 additions & 8 deletions pkg/resourcecreator/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,17 @@ func envVars(app *nais.Application) []corev1.EnvVar {
func podObjectMeta(app *nais.Application) metav1.ObjectMeta {
objectMeta := app.CreateObjectMeta()

port := app.Spec.Prometheus.Port
if len(port) == 0 {
port = strconv.Itoa(app.Spec.Port)
}
if app.Spec.Prometheus.Path != "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ingen grunn til å lage annotation hvis man ikke skal scrape.

port := app.Spec.Prometheus.Port
if len(port) == 0 {
port = strconv.Itoa(app.Spec.Port)
}

objectMeta.Annotations = map[string]string{
"prometheus.io/scrape": strconv.FormatBool(app.Spec.Prometheus.Enabled),
"prometheus.io/port": port,
"prometheus.io/path": app.Spec.Prometheus.Path,
objectMeta.Annotations = map[string]string{
"prometheus.io/scrape": "true",
"prometheus.io/port": port,
"prometheus.io/path": app.Spec.Prometheus.Path,
}
}
if len(app.Spec.Logformat) > 0 {
objectMeta.Annotations["nais.io/logformat"] = app.Spec.Logformat
Expand Down
14 changes: 7 additions & 7 deletions pkg/resourcecreator/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestDeployment(t *testing.T) {

t.Run("prometheus port defaults to application port", func(t *testing.T) {
app := fixtures.MinimalApplication()
app.Spec.Prometheus.Enabled = true
app.Spec.Prometheus.Path = "/metrics"
app.Spec.Port = 12345
err := nais.ApplyDefaults(app)
assert.NoError(t, err)
Expand All @@ -92,24 +92,24 @@ func TestDeployment(t *testing.T) {
deploy, err := resourcecreator.Deployment(app, opts)
assert.Nil(t, err)

assert.Equal(t, "true", deploy.Spec.Template.Annotations["prometheus.io/scrape"])
assert.Equal(t, app.Spec.Prometheus.Path, deploy.Spec.Template.Annotations["prometheus.io/path"])
assert.Equal(t, strconv.Itoa(app.Spec.Port), deploy.Spec.Template.Annotations["prometheus.io/port"])
})

t.Run("prometheus is set up correctly", func(t *testing.T) {
t.Run("prometheus is disabled if no path is set", func(t *testing.T) {
app := fixtures.MinimalApplication()
app.Spec.Prometheus.Path = "/my/metrics"
app.Spec.Prometheus.Port = "1234"
app.Spec.Prometheus.Enabled = true
err := nais.ApplyDefaults(app)
assert.NoError(t, err)

opts := resourcecreator.NewResourceOptions()
deploy, err := resourcecreator.Deployment(app, opts)
assert.Nil(t, err)

assert.Equal(t, strconv.FormatBool(app.Spec.Prometheus.Enabled), deploy.Spec.Template.Annotations["prometheus.io/scrape"])
assert.Equal(t, app.Spec.Prometheus.Path, deploy.Spec.Template.Annotations["prometheus.io/path"])
assert.Equal(t, app.Spec.Prometheus.Port, deploy.Spec.Template.Annotations["prometheus.io/port"])
assert.Empty(t, deploy.Spec.Template.Annotations["prometheus.io/scrape"])
assert.Empty(t, deploy.Spec.Template.Annotations["prometheus.io/path"])
assert.Empty(t, deploy.Spec.Template.Annotations["prometheus.io/port"])
})

t.Run("certificate authority files and configuration is set according to spec", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcecreator/resourcecreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func Create(app *nais.Application, resourceOptions ResourceOptions) (ResourceOpe

serviceRoleBindingPrometheus := ServiceRoleBindingPrometheus(app)
operation = OperationCreateOrUpdate
if !app.Spec.Prometheus.Enabled {
if app.Spec.Prometheus.Path == "" {
operation = OperationDeleteIfExists
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/resourcecreator/resourcecreator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestCreate(t *testing.T) {
opts := resourcecreator.NewResourceOptions()
opts.AccessPolicy = true
app.Spec.AccessPolicy.Inbound.Rules = []nais.AccessPolicyRule{{"otherapp", "othernamespace"}}
app.Spec.Prometheus.Enabled = true
app.Spec.Prometheus.Path = "/metrics"

err := nais.ApplyDefaults(app)
assert.NoError(t, err)
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestCreate(t *testing.T) {

opts := resourcecreator.NewResourceOptions()

app.Spec.Prometheus.Enabled = false
app.Spec.Prometheus.Path = ""
opts.AccessPolicy = true

resources, err := resourcecreator.Create(app, opts)
Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcecreator/servicerole.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func ServiceRole(app *nais.Application) *istio_crd.ServiceRole {
}

func ServiceRolePrometheus(app *nais.Application) (serviceRolePrometheus *istio_crd.ServiceRole) {
if !app.Spec.Prometheus.Enabled {
if app.Spec.Prometheus.Path == "" {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resourcecreator/servicerole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestIstio(t *testing.T) {

t.Run("service role and service role binding created, with matching naming, when prometheus is enabled", func(t *testing.T) {
app := fixtures.MinimalApplication()
app.Spec.Prometheus.Enabled = true
app.Spec.Prometheus.Path = "/metrics"
err := nais.ApplyDefaults(app)
assert.NoError(t, err)

Expand Down