Skip to content

Commit

Permalink
monitoring: apply common label options to monitoring resources
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Jun 9, 2020
1 parent 9705d9d commit 70ecfbb
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 186 deletions.
63 changes: 14 additions & 49 deletions pkg/3scale/amp/component/apicast_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package component
import (
"fmt"

appsv1alpha1 "github.com/3scale/3scale-operator/pkg/apis/apps/v1alpha1"
"github.com/3scale/3scale-operator/pkg/assets"
"github.com/3scale/3scale-operator/pkg/common"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
Expand All @@ -14,20 +13,15 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

func ApicastProductionMonitoringService() *v1.Service {
func (apicast *Apicast) ApicastProductionMonitoringService() *v1.Service {
return &v1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-production-metrics",
Labels: map[string]string{
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "apicast",
"threescale_component_element": "production",
"monitoring-key": common.MonitoringKey,
},
Name: "apicast-production-metrics",
Labels: apicast.Options.ProductionMonitoringLabels,
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand All @@ -43,20 +37,15 @@ func ApicastProductionMonitoringService() *v1.Service {
}
}

func ApicastStagingMonitoringService() *v1.Service {
func (apicast *Apicast) ApicastStagingMonitoringService() *v1.Service {
return &v1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-staging-metrics",
Labels: map[string]string{
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "apicast",
"threescale_component_element": "staging",
"monitoring-key": common.MonitoringKey,
},
Name: "apicast-staging-metrics",
Labels: apicast.Options.StagingMonitoringLabels,
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand All @@ -72,17 +61,11 @@ func ApicastStagingMonitoringService() *v1.Service {
}
}

func ApicastProductionServiceMonitor() *monitoringv1.ServiceMonitor {
func (apicast *Apicast) ApicastProductionServiceMonitor() *monitoringv1.ServiceMonitor {
return &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-production",
Labels: map[string]string{
// TODO from options
"monitoring-key": common.MonitoringKey,
"threescale_component": "apicast",
"threescale_component_element": "production",
"app": appsv1alpha1.Default3scaleAppLabel,
},
Name: "apicast-production",
Labels: apicast.Options.ProductionMonitoringLabels,
},
Spec: monitoringv1.ServiceMonitorSpec{
Endpoints: []monitoringv1.Endpoint{{
Expand All @@ -91,29 +74,17 @@ func ApicastProductionServiceMonitor() *monitoringv1.ServiceMonitor {
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
// TODO from options
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "apicast",
"threescale_component_element": "production",
"monitoring-key": common.MonitoringKey,
},
MatchLabels: apicast.Options.ProductionMonitoringLabels,
},
},
}
}

func ApicastStagingServiceMonitor() *monitoringv1.ServiceMonitor {
func (apicast *Apicast) ApicastStagingServiceMonitor() *monitoringv1.ServiceMonitor {
return &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "apicast-staging",
Labels: map[string]string{
// TODO from options
"monitoring-key": common.MonitoringKey,
"threescale_component": "apicast",
"threescale_component_element": "staging",
"app": appsv1alpha1.Default3scaleAppLabel,
},
Name: "apicast-staging",
Labels: apicast.Options.StagingMonitoringLabels,
},
Spec: monitoringv1.ServiceMonitorSpec{
Endpoints: []monitoringv1.Endpoint{{
Expand All @@ -122,13 +93,7 @@ func ApicastStagingServiceMonitor() *monitoringv1.ServiceMonitor {
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
// TODO from options
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "apicast",
"threescale_component_element": "staging",
"monitoring-key": common.MonitoringKey,
},
MatchLabels: apicast.Options.StagingMonitoringLabels,
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/3scale/amp/component/apicast_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type ApicastOptions struct {
CommonProductionLabels map[string]string `validate:"required"`
StagingPodTemplateLabels map[string]string `validate:"required"`
ProductionPodTemplateLabels map[string]string `validate:"required"`
StagingMonitoringLabels map[string]string `validate:"required"`
ProductionMonitoringLabels map[string]string `validate:"required"`
}

func NewApicastOptions() *ApicastOptions {
Expand Down
63 changes: 14 additions & 49 deletions pkg/3scale/amp/component/backend_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package component
import (
"fmt"

appsv1alpha1 "github.com/3scale/3scale-operator/pkg/apis/apps/v1alpha1"
"github.com/3scale/3scale-operator/pkg/assets"
"github.com/3scale/3scale-operator/pkg/common"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
Expand All @@ -14,20 +13,15 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

func BackendListenerMonitoringService() *v1.Service {
func (backend *Backend) BackendListenerMonitoringService() *v1.Service {
return &v1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "backend-listener-metrics",
Labels: map[string]string{
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "backend",
"threescale_component_element": "listener",
"monitoring-key": common.MonitoringKey,
},
Name: "backend-listener-metrics",
Labels: backend.Options.ListenerMonitoringLabels,
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand All @@ -43,17 +37,11 @@ func BackendListenerMonitoringService() *v1.Service {
}
}

func BackendListenerServiceMonitor() *monitoringv1.ServiceMonitor {
func (backend *Backend) BackendListenerServiceMonitor() *monitoringv1.ServiceMonitor {
return &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "backend-listener",
Labels: map[string]string{
// TODO from options
"monitoring-key": common.MonitoringKey,
"threescale_component": "backend",
"threescale_component_element": "listener",
"app": appsv1alpha1.Default3scaleAppLabel,
},
Name: "backend-listener",
Labels: backend.Options.ListenerMonitoringLabels,
},
Spec: monitoringv1.ServiceMonitorSpec{
Endpoints: []monitoringv1.Endpoint{{
Expand All @@ -62,32 +50,21 @@ func BackendListenerServiceMonitor() *monitoringv1.ServiceMonitor {
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
// TODO from options
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "backend",
"threescale_component_element": "listener",
"monitoring-key": common.MonitoringKey,
},
MatchLabels: backend.Options.ListenerMonitoringLabels,
},
},
}
}

func BackendWorkerMonitoringService() *v1.Service {
func (backend *Backend) BackendWorkerMonitoringService() *v1.Service {
return &v1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "backend-worker-metrics",
Labels: map[string]string{
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "backend",
"threescale_component_element": "worker",
"monitoring-key": common.MonitoringKey,
},
Name: "backend-worker-metrics",
Labels: backend.Options.WorkerMonitoringLabels,
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand All @@ -103,17 +80,11 @@ func BackendWorkerMonitoringService() *v1.Service {
}
}

func BackendWorkerServiceMonitor() *monitoringv1.ServiceMonitor {
func (backend *Backend) BackendWorkerServiceMonitor() *monitoringv1.ServiceMonitor {
return &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "backend-worker",
Labels: map[string]string{
// TODO from options
"monitoring-key": common.MonitoringKey,
"threescale_component": "backend",
"threescale_component_element": "worker",
"app": appsv1alpha1.Default3scaleAppLabel,
},
Name: "backend-worker",
Labels: backend.Options.WorkerMonitoringLabels,
},
Spec: monitoringv1.ServiceMonitorSpec{
Endpoints: []monitoringv1.Endpoint{{
Expand All @@ -122,13 +93,7 @@ func BackendWorkerServiceMonitor() *monitoringv1.ServiceMonitor {
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
// TODO from options
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "backend",
"threescale_component_element": "worker",
"monitoring-key": common.MonitoringKey,
},
MatchLabels: backend.Options.WorkerMonitoringLabels,
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/3scale/amp/component/backend_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type BackendOptions struct {
ListenerPodTemplateLabels map[string]string `validate:"required"`
WorkerPodTemplateLabels map[string]string `validate:"required"`
CronPodTemplateLabels map[string]string `validate:"required"`
ListenerMonitoringLabels map[string]string `validate:"required"`
WorkerMonitoringLabels map[string]string `validate:"required"`
}

func NewBackendOptions() *BackendOptions {
Expand Down
32 changes: 7 additions & 25 deletions pkg/3scale/amp/component/system_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package component
import (
"fmt"

appsv1alpha1 "github.com/3scale/3scale-operator/pkg/apis/apps/v1alpha1"
"github.com/3scale/3scale-operator/pkg/assets"
"github.com/3scale/3scale-operator/pkg/common"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
Expand All @@ -14,20 +13,15 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
)

func SystemSidekiqMonitoringService() *v1.Service {
func (system *System) SystemSidekiqMonitoringService() *v1.Service {
return &v1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "system-sidekiq-metrics",
Labels: map[string]string{
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "system",
"threescale_component_element": "sidekiq",
"monitoring-key": common.MonitoringKey,
},
Name: "system-sidekiq-metrics",
Labels: system.Options.SidekiqMonitoringLabels,
},
Spec: v1.ServiceSpec{
Ports: []v1.ServicePort{
Expand All @@ -43,17 +37,11 @@ func SystemSidekiqMonitoringService() *v1.Service {
}
}

func SystemSidekiqServiceMonitor() *monitoringv1.ServiceMonitor {
func (system *System) SystemSidekiqServiceMonitor() *monitoringv1.ServiceMonitor {
return &monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "system-sidekiq",
Labels: map[string]string{
// TODO from options
"threescale_component": "system",
"threescale_component_element": "sidekiq",
"monitoring-key": common.MonitoringKey,
"app": appsv1alpha1.Default3scaleAppLabel,
},
Name: "system-sidekiq",
Labels: system.Options.SidekiqMonitoringLabels,
},
Spec: monitoringv1.ServiceMonitorSpec{
Endpoints: []monitoringv1.Endpoint{{
Expand All @@ -62,13 +50,7 @@ func SystemSidekiqServiceMonitor() *monitoringv1.ServiceMonitor {
Scheme: "http",
}},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
// TODO from options
"app": appsv1alpha1.Default3scaleAppLabel,
"threescale_component": "system",
"threescale_component_element": "sidekiq",
"monitoring-key": common.MonitoringKey,
},
MatchLabels: system.Options.SidekiqMonitoringLabels,
},
},
}
Expand Down
1 change: 1 addition & 0 deletions pkg/3scale/amp/component/system_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type SystemOptions struct {
SphinxPodTemplateLabels map[string]string `validate:"required"`
MemcachedLabels map[string]string `validate:"required"`
SMTPLabels map[string]string `validate:"required"`
SidekiqMonitoringLabels map[string]string `validate:"required"`
}

func NewSystemOptions() *SystemOptions {
Expand Down
Loading

0 comments on commit 70ecfbb

Please sign in to comment.