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

Only scrape istio-proxy #390

Merged
merged 2 commits into from
Jan 20, 2024
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
2 changes: 1 addition & 1 deletion controllers/application/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *ApplicationReconciler) reconcileService(ctx context.Context, applicatio
service.SetLabels(labels)

ports := append(getAdditionalPorts(application.Spec.AdditionalPorts), getServicePort(application.Spec.Port, application.Spec.AppProtocol))
if r.IsIstioEnabledForNamespace(ctx, application.Namespace) && application.Spec.Prometheus != nil {
if r.IsIstioEnabledForNamespace(ctx, application.Namespace) {
ports = append(ports, defaultPrometheusPort)
}

Expand Down
26 changes: 7 additions & 19 deletions controllers/application/service_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (r *ApplicationReconciler) reconcileServiceMonitor(ctx context.Context, app
return util.RequeueWithError(err)
}

if application.Spec.Prometheus == nil {
evenh marked this conversation as resolved.
Show resolved Hide resolved
if !r.IsIstioEnabledForNamespace(ctx, application.Namespace) {
err := client.IgnoreNotFound(r.GetClient().Delete(ctx, &serviceMonitor))
if err != nil {
r.SetControllerError(ctx, application, controllerName, err)
Expand Down Expand Up @@ -61,7 +61,12 @@ func (r *ApplicationReconciler) reconcileServiceMonitor(ctx context.Context, app
NamespaceSelector: pov1.NamespaceSelector{
MatchNames: []string{application.Namespace},
},
Endpoints: r.determineEndpoint(ctx, application),
Endpoints: []pov1.Endpoint{
{
Path: util.IstioMetricsPath,
TargetPort: &util.IstioMetricsPortName,
},
},
}

return nil
Expand All @@ -71,20 +76,3 @@ func (r *ApplicationReconciler) reconcileServiceMonitor(ctx context.Context, app

return util.RequeueWithError(err)
}

func (r *ApplicationReconciler) determineEndpoint(ctx context.Context, application *skiperatorv1alpha1.Application) []pov1.Endpoint {
ep := pov1.Endpoint{
Path: util.IstioMetricsPath, TargetPort: &util.IstioMetricsPortName,
}

if r.IsIstioEnabledForNamespace(ctx, application.Namespace) {
return []pov1.Endpoint{ep}
}

return []pov1.Endpoint{
{
Path: application.Spec.Prometheus.Path,
TargetPort: &application.Spec.Prometheus.Port,
},
}
}
1 change: 1 addition & 0 deletions controllers/skipjob/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (r *SKIPJobReconciler) reconcileNetworkPolicy(ctx context.Context, skipJob
Namespaces: &namespaces,
Name: skipJob.Name,
RelatedServices: &egressServices,
IstioEnabled: r.IsIstioEnabledForNamespace(ctx, skipJob.Namespace),
}

netpolSpec := networking.CreateNetPolSpec(netpolOpts)
Expand Down
22 changes: 6 additions & 16 deletions controllers/skipjob/pod_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,14 @@ func (r *SKIPJobReconciler) reconcilePodMonitor(ctx context.Context, skipJob *sk
NamespaceSelector: pov1.NamespaceSelector{
MatchNames: []string{skipJob.Namespace},
},
PodMetricsEndpoints: r.determineEndpoint(ctx, skipJob),
PodMetricsEndpoints: []pov1.PodMetricsEndpoint{
{
Path: util.IstioMetricsPath,
TargetPort: &util.IstioMetricsPortName,
},
},
}
return nil
})
return util.RequeueWithError(err)
}

func (r *SKIPJobReconciler) determineEndpoint(ctx context.Context, application *skiperatorv1alpha1.SKIPJob) []pov1.PodMetricsEndpoint {
ep := pov1.PodMetricsEndpoint{
Path: util.IstioMetricsPath, TargetPort: &util.IstioMetricsPortName,
}
if r.IsIstioEnabledForNamespace(ctx, application.Namespace) {
return []pov1.PodMetricsEndpoint{ep}
}
return []pov1.PodMetricsEndpoint{
{
Path: application.Spec.Prometheus.Path,
TargetPort: &application.Spec.Prometheus.Port,
},
}
}
4 changes: 2 additions & 2 deletions pkg/resourcegenerator/core/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func getContainerPorts(application *skiperatorv1alpha1.Application, opts PodOpts
})
}

// Expose merged Prometheus telemetry to Service, so it can be picked up from ServiceMonitor
if application.Spec.Prometheus != nil && opts.IstioEnabled {
// Expose Prometheus telemetry to Service, so it can be picked up from ServiceMonitor
if opts.IstioEnabled {
containerPorts = append(containerPorts, corev1.ContainerPort{
Name: util.IstioMetricsPortName.StrVal,
ContainerPort: util.IstioMetricsPortNumber.IntVal,
Expand Down
13 changes: 3 additions & 10 deletions pkg/resourcegenerator/networking/network_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ func getIngressRules(opts NetPolOpts) []networkingv1.NetworkPolicyIngressRule {
}
}

// If Prometheus metrics are exposed, allow grafana-agent to scrape
if opts.PrometheusConfig != nil {
// Allow grafana-agent to scrape
if opts.IstioEnabled {
promScrapeRule := networkingv1.NetworkPolicyIngressRule{
From: []networkingv1.NetworkPolicyPeer{
{
Expand All @@ -176,7 +176,7 @@ func getIngressRules(opts NetPolOpts) []networkingv1.NetworkPolicyIngressRule {
},
Ports: []networkingv1.NetworkPolicyPort{
{
Port: determinePrometheusScrapePort(opts.PrometheusConfig, opts.IstioEnabled),
Port: util.PointTo(util.IstioMetricsPortName),
},
},
}
Expand Down Expand Up @@ -287,10 +287,3 @@ func getIngressGatewayLabel(isInternal bool) map[string]string {
return map[string]string{"app": "istio-ingress-external"}
}
}

func determinePrometheusScrapePort(prometheusConfig *skiperatorv1alpha1.PrometheusConfig, istioEnabled bool) *intstr.IntOrString {
if istioEnabled {
return util.PointTo(util.IstioMetricsPortName)
}
return util.PointTo(prometheusConfig.Port)
}
2 changes: 1 addition & 1 deletion pkg/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var CommonAnnotations = map[string]string{
const SkiperatorUser = int64(150)

var (
IstioMetricsPortNumber = intstr.FromInt(15020)
IstioMetricsPortNumber = intstr.FromInt32(15020)
IstioMetricsPortName = intstr.FromString("istio-metrics")
IstioMetricsPath = "/stats/prometheus"

Expand Down
12 changes: 0 additions & 12 deletions tests/application/service-monitor/chainsaw-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ spec:
skipDelete: false
namespace: service-monitor-ns
steps:
- try:
- create:
file: multiple-applications.yaml
- assert:
file: multiple-applications-assert.yaml
- try:
- apply:
file: patch-single-application.yaml
- assert:
file: patch-single-application-assert.yaml
- error:
file: patch-single-application-error.yaml
- try:
- create:
file: application-istio.yaml
Expand Down
159 changes: 0 additions & 159 deletions tests/application/service-monitor/multiple-applications-assert.yaml

This file was deleted.

42 changes: 0 additions & 42 deletions tests/application/service-monitor/multiple-applications.yaml

This file was deleted.

Loading
Loading