Skip to content

Commit a717988

Browse files
sradcoAI Assistant
andcommitted
management: add CRD support and create alert rule API
Add AlertingRule, AlertRelabelConfig, and RelabeledRules CRD interfaces with the management client, router, server wiring, and POST /api/v1/alerting/rules endpoint. 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 ba3697b commit a717988

35 files changed

Lines changed: 2919 additions & 118 deletions

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RUN make install-backend
2525

2626
COPY cmd/ cmd/
2727
COPY pkg/ pkg/
28+
COPY internal/ internal/
2829

2930
ENV GOEXPERIMENT=strictfipsruntime
3031
ENV CGO_ENABLED=1

Dockerfile.dev

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ RUN go mod download
2828

2929
COPY cmd/ cmd/
3030
COPY pkg/ pkg/
31+
COPY internal/ internal/
3132

3233
RUN go build -mod=mod -o plugin-backend cmd/plugin-backend.go
3334

Dockerfile.dev-mcp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ RUN go mod download
3131

3232
COPY cmd/ cmd/
3333
COPY pkg/ pkg/
34+
COPY internal/ internal/
3435

3536
RUN go build -mod=mod -o plugin-backend cmd/plugin-backend.go
3637

Dockerfile.devspace

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ RUN make install-backend
2020
COPY config/ config/
2121
COPY cmd/ cmd/
2222
COPY pkg/ pkg/
23+
COPY internal/ internal/
2324

2425
RUN make build-backend
2526

Dockerfile.konflux

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ RUN make install-backend
2828

2929
COPY cmd/ cmd/
3030
COPY pkg/ pkg/
31+
COPY internal/ internal/
3132

3233
ENV GOEXPERIMENT=strictfipsruntime
3334
ENV CGO_ENABLED=1

Dockerfile.mcp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ RUN make install-backend
2828

2929
COPY cmd/ cmd/
3030
COPY pkg/ pkg/
31+
COPY internal/ internal/
3132

3233
ENV GOOS=${TARGETOS:-linux}
3334
ENV GOARCH=${TARGETARCH}

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ lint-frontend:
4141
lint-backend:
4242
go mod tidy
4343
go fmt ./cmd/
44-
go fmt ./pkg/
44+
go fmt ./pkg/... ./internal/...
4545

4646
.PHONY: install-backend
4747
install-backend:
@@ -57,7 +57,11 @@ start-backend:
5757

5858
.PHONY: test-backend
5959
test-backend:
60-
go test ./pkg/... -v
60+
go test ./pkg/... ./internal/... -v
61+
62+
.PHONY: test-e2e
63+
test-e2e:
64+
PLUGIN_URL=http://localhost:9001 go test -v -timeout=150m -count=1 ./test/e2e
6165

6266
.PHONY: build-image
6367
build-image:

go.mod

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ require (
2525
)
2626

2727
require (
28-
github.com/beorn7/perks v1.0.1 // indirect
2928
github.com/cespare/xxhash/v2 v2.3.0 // indirect
3029
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
31-
github.com/dennwc/varint v1.0.0 // indirect
3230
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
3331
github.com/felixge/httpsnoop v1.0.4 // indirect
3432
github.com/fsnotify/fsnotify v1.9.0 // indirect
@@ -61,12 +59,8 @@ require (
6159
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6260
github.com/pkg/errors v0.9.1 // indirect
6361
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
64-
github.com/prometheus/client_golang v1.23.2 // indirect
6562
github.com/prometheus/client_model v0.6.2 // indirect
66-
github.com/prometheus/procfs v0.16.1 // indirect
67-
github.com/spf13/pflag v1.0.6 // indirect
6863
github.com/x448/float16 v0.8.4 // indirect
69-
go.uber.org/atomic v1.11.0 // indirect
7064
go.yaml.in/yaml/v2 v2.4.3 // indirect
7165
go.yaml.in/yaml/v3 v3.0.4 // indirect
7266
golang.org/x/net v0.46.0 // indirect

go.sum

Lines changed: 0 additions & 106 deletions
Large diffs are not rendered by default.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package managementrouter
2+
3+
import (
4+
"encoding/json"
5+
"net/http"
6+
7+
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
8+
9+
"github.com/openshift/monitoring-plugin/pkg/management"
10+
)
11+
12+
type CreateAlertRuleRequest struct {
13+
AlertingRule *monitoringv1.Rule `json:"alertingRule,omitempty"`
14+
PrometheusRule *management.PrometheusRuleOptions `json:"prometheusRule,omitempty"`
15+
}
16+
17+
type CreateAlertRuleResponse struct {
18+
Id string `json:"id"`
19+
}
20+
21+
func (hr *httpRouter) CreateAlertRule(w http.ResponseWriter, req *http.Request) {
22+
var payload CreateAlertRuleRequest
23+
if err := json.NewDecoder(req.Body).Decode(&payload); err != nil {
24+
writeError(w, http.StatusBadRequest, "invalid request body")
25+
return
26+
}
27+
28+
if payload.AlertingRule == nil {
29+
writeError(w, http.StatusBadRequest, "alertingRule is required")
30+
return
31+
}
32+
33+
alertRule := *payload.AlertingRule
34+
35+
var (
36+
id string
37+
err error
38+
)
39+
40+
if payload.PrometheusRule != nil {
41+
id, err = hr.managementClient.CreateUserDefinedAlertRule(req.Context(), alertRule, *payload.PrometheusRule)
42+
} else {
43+
id, err = hr.managementClient.CreatePlatformAlertRule(req.Context(), alertRule)
44+
}
45+
46+
if err != nil {
47+
handleError(w, err)
48+
return
49+
}
50+
51+
w.Header().Set("Content-Type", "application/json")
52+
w.WriteHeader(http.StatusCreated)
53+
_ = json.NewEncoder(w).Encode(CreateAlertRuleResponse{Id: id})
54+
}

0 commit comments

Comments
 (0)