Skip to content

Commit af220e9

Browse files
sradcoAI Assistant
andcommitted
k8s: add alert listing/query and filter primitives
Add PrometheusAlerts implementation with: - Alert fetching from platform and user-workload Prometheus/Thanos - Rule group fetching with namespace-scoped Thanos tenancy queries - State-based filtering (firing, pending, silenced) - Label-based flat filtering with key=value matching - TLS transport with service CA for in-cluster communication Signed-off-by: Shirly Radco <sradco@redhat.com> Signed-off-by: João Vilaça <jvilaca@redhat.com> Signed-off-by: Aviv Litman <alitman@redhat.com> Co-authored-by: AI Assistant <noreply@cursor.com>
1 parent 6e7d30b commit af220e9

6 files changed

Lines changed: 1215 additions & 0 deletions

File tree

pkg/k8s/client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"k8s.io/client-go/rest"
99

1010
osmv1client "github.com/openshift/client-go/monitoring/clientset/versioned"
11+
routeclient "github.com/openshift/client-go/route/clientset/versioned"
1112
monitoringv1client "github.com/prometheus-operator/prometheus-operator/pkg/client/versioned"
1213
"github.com/sirupsen/logrus"
1314
)
@@ -22,6 +23,8 @@ type client struct {
2223
osmv1clientset *osmv1client.Clientset
2324
config *rest.Config
2425

26+
prometheusAlerts *prometheusAlerts
27+
2528
prometheusRuleManager *prometheusRuleManager
2629
namespaceManager *namespaceManager
2730
}
@@ -42,6 +45,11 @@ func NewClient(ctx context.Context, config *rest.Config) (Client, error) {
4245
return nil, fmt.Errorf("failed to create osmv1 clientset: %w", err)
4346
}
4447

48+
routeClientset, err := routeclient.NewForConfig(config)
49+
if err != nil {
50+
return nil, fmt.Errorf("failed to create route clientset: %w", err)
51+
}
52+
4553
c := &client{
4654
clientset: clientset,
4755
monitoringv1clientset: monitoringv1clientset,
@@ -54,6 +62,8 @@ func NewClient(ctx context.Context, config *rest.Config) (Client, error) {
5462
return nil, fmt.Errorf("failed to create PrometheusRule manager: %w", err)
5563
}
5664

65+
c.prometheusAlerts = newPrometheusAlerts(routeClientset, clientset.CoreV1(), config, c.prometheusRuleManager)
66+
5767
c.namespaceManager, err = newNamespaceManager(ctx, clientset)
5868
if err != nil {
5969
return nil, fmt.Errorf("failed to create namespace manager: %w", err)
@@ -70,6 +80,10 @@ func (c *client) TestConnection(_ context.Context) error {
7080
return nil
7181
}
7282

83+
func (c *client) PrometheusAlerts() PrometheusAlertsInterface {
84+
return c.prometheusAlerts
85+
}
86+
7387
func (c *client) PrometheusRules() PrometheusRuleInterface {
7488
return c.prometheusRuleManager
7589
}

pkg/k8s/const.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,33 @@ package k8s
22

33
const (
44
ClusterMonitoringNamespace = "openshift-monitoring"
5+
6+
PlatformRouteNamespace = "openshift-monitoring"
7+
PlatformRouteName = "prometheus-k8s"
8+
PlatformAlertmanagerRouteName = "alertmanager-main"
9+
UserWorkloadRouteNamespace = "openshift-user-workload-monitoring"
10+
UserWorkloadRouteName = "prometheus-user-workload"
11+
UserWorkloadAlertmanagerRouteName = "alertmanager-user-workload"
12+
PrometheusAlertsPath = "/v1/alerts"
13+
PrometheusRulesPath = "/v1/rules"
14+
AlertmanagerAlertsPath = "/api/v2/alerts"
15+
UserWorkloadAlertmanagerPort = 9095
16+
UserWorkloadPrometheusServiceName = "prometheus-user-workload-web"
17+
UserWorkloadPrometheusPort = 9090
18+
19+
ThanosQuerierNamespace = "openshift-monitoring"
20+
ThanosQuerierServiceName = "thanos-querier"
21+
ThanosQuerierTenancyRulesPortName = "tenancy-rules"
22+
DefaultThanosQuerierTenancyRulesPort = 9093
23+
ThanosQuerierTenancyAlertsPath = "/api/v1/alerts"
24+
ThanosQuerierTenancyRulesPath = "/api/v1/rules"
25+
ServiceCAPath = "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
26+
27+
AlertSourceLabel = "openshift_io_alert_source"
28+
AlertSourcePlatform = "platform"
29+
AlertSourceUser = "user"
30+
AlertBackendLabel = "openshift_io_alert_backend"
31+
AlertBackendAM = "alertmanager"
32+
AlertBackendProm = "prometheus"
33+
AlertBackendThanos = "thanos"
534
)

0 commit comments

Comments
 (0)