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

fix: update monitor mutation to not overwrite explicitly defined scrape class #582

Merged
merged 7 commits into from
Jul 19, 2024
8 changes: 5 additions & 3 deletions src/pepr/prometheus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ServiceMonitorEndpoint,
ServiceMonitorScheme,
} from "../operator/crd";

// configure subproject logger
const log = setupLogger(Component.PROMETHEUS);

Expand All @@ -25,7 +24,7 @@ const { When } = prometheus;
When(PrometheusServiceMonitor)
.IsCreatedOrUpdated()
.Mutate(async sm => {
if (sm.Raw.spec === undefined) {
if (sm.Raw.spec === undefined || sm.Raw.spec.scrapeClass != undefined) {
return;
}

Expand All @@ -39,6 +38,7 @@ When(PrometheusServiceMonitor)
`Mutating scrapeClass to exempt ServiceMonitor ${sm.Raw.metadata?.name} from default scrapeClass mTLS config`,
);
sm.Raw.spec.scrapeClass = "exempt";

return;
} else {
log.info(`Patching service monitor ${sm.Raw.metadata?.name} for mTLS metrics`);
Expand All @@ -64,7 +64,7 @@ When(PrometheusServiceMonitor)
When(PrometheusPodMonitor)
.IsCreatedOrUpdated()
.Mutate(async pm => {
if (pm.Raw.spec === undefined) {
if (pm.Raw.spec === undefined || pm.Raw.spec.scrapeClass != undefined) {
return;
}

Expand All @@ -74,6 +74,7 @@ When(PrometheusPodMonitor)
`Mutating scrapeClass to exempt PodMonitor ${pm.Raw.metadata?.name} from default scrapeClass mTLS config`,
);
pm.Raw.spec.scrapeClass = "exempt";

return;
} else {
log.info(`Patching pod monitor ${pm.Raw.metadata?.name} for mTLS metrics`);
Expand Down Expand Up @@ -102,5 +103,6 @@ async function isIstioInjected(monitor: PrometheusServiceMonitor | PrometheusPod
return true;
}
}

return false;
}