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

Added monitoring endpoint #100

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a17a509
Added monitoring endpoint
p-strusiewiczsurmacki-mobica Feb 28, 2024
3b873c0
Fixed linter issues
p-strusiewiczsurmacki-mobica Feb 28, 2024
561170b
Fixed issues from CR and added k8s client
p-strusiewiczsurmacki-mobica Mar 6, 2024
2c1b70e
Added initial global endpoint
p-strusiewiczsurmacki-mobica Mar 6, 2024
f9e1d11
Added global endpoint
p-strusiewiczsurmacki-mobica Mar 7, 2024
38920ff
Added asynchronous GET calls
p-strusiewiczsurmacki-mobica Mar 8, 2024
aafc408
Fixed linter issues
p-strusiewiczsurmacki-mobica Mar 8, 2024
0a6fcf6
Made label selector more specific
p-strusiewiczsurmacki-mobica Mar 12, 2024
e0d5249
Added basic unit tests
p-strusiewiczsurmacki-mobica Mar 12, 2024
0e99394
Removed redundant const
p-strusiewiczsurmacki-mobica Mar 12, 2024
4d4ade2
Fixed linter issues
p-strusiewiczsurmacki-mobica Mar 12, 2024
b1ba4dd
ShowBGP - protocol ip will be accepted as ipv4
p-strusiewiczsurmacki-mobica Mar 12, 2024
dfb59cf
Fixed json generation
p-strusiewiczsurmacki-mobica Mar 12, 2024
869560e
Service/endpoint based discovery used instead of pod based discovery
p-strusiewiczsurmacki-mobica Mar 12, 2024
47e7e9b
Fixed typo
p-strusiewiczsurmacki-mobica Mar 13, 2024
f686f93
Updated unit tests
p-strusiewiczsurmacki-mobica Mar 13, 2024
58b5509
Fixed linter issues
p-strusiewiczsurmacki-mobica Mar 13, 2024
fdc0e00
Reworked request passing and added more unit tests
p-strusiewiczsurmacki-mobica Mar 13, 2024
c5080b1
Removed redundant line
p-strusiewiczsurmacki-mobica Mar 13, 2024
b499702
Fixed URL building
p-strusiewiczsurmacki-mobica Mar 13, 2024
595daa4
Removed redundant code
p-strusiewiczsurmacki-mobica Mar 13, 2024
6861d81
Fixed linter issues
p-strusiewiczsurmacki-mobica Mar 13, 2024
dfe0051
Reworked pod discovery
p-strusiewiczsurmacki-mobica Mar 15, 2024
cb9be8c
Status service and namespace will be now configured using env variables
p-strusiewiczsurmacki-mobica Mar 15, 2024
9aefc32
Fixed linter issues
p-strusiewiczsurmacki-mobica Mar 15, 2024
2ec4a6a
CR related changes
p-strusiewiczsurmacki-mobica Apr 10, 2024
4ca3c42
Update pkg/monitoring/endpoint.go
p-strusiewiczsurmacki-mobica Apr 18, 2024
3c402b2
Separate HHTTP servers for frr-exporter and monitoring endpoint. Sepa…
p-strusiewiczsurmacki-mobica Apr 18, 2024
d5f5df6
Ranamed PassRequest function to QueryAll
p-strusiewiczsurmacki-mobica Apr 18, 2024
0744b4c
Separated passRequest go routine as suggested in the CR
p-strusiewiczsurmacki-mobica Apr 18, 2024
77d7182
Sanitized inputs
p-strusiewiczsurmacki-mobica Apr 18, 2024
0448608
Fixed logging and other minor issues
p-strusiewiczsurmacki-mobica Apr 18, 2024
71cb862
Joined monitoring endpoint HTTP server and frr collector HTTP server …
p-strusiewiczsurmacki-mobica Apr 19, 2024
0ba752b
Fixed validation
p-strusiewiczsurmacki-mobica Apr 30, 2024
1827b80
Fixed linter issue
p-strusiewiczsurmacki-mobica Apr 30, 2024
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
22 changes: 21 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

# Image URL to use all building/pushing image targets
IMG ?= ghcr.io/telekom/das-schiff-network-operator:latest
# Sidecar image URL to use all building/pushing image targets
SIDECAR_IMG ?= ghcr.io/telekom/frr-exporter:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25

Expand Down Expand Up @@ -69,7 +71,7 @@ test: manifests generate fmt vet envtest ## Run tests.
build: generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/manager/main.go

.PHONY: build
.PHONY: sidecar-build
sidecar-build: build
go build -o bin/frr-exporter cmd/frr-exporter/main.go

Expand All @@ -81,10 +83,19 @@ run: manifests generate fmt vet ## Run a controller from your host.
docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .

.PHONY: docker-build-sidecar
docker-build-sidecar: test ## Build docker image with the manager.
docker build -t ${SIDECAR_IMG} -f frr-exporter.Dockerfile .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}

.PHONY: docker-push-sidecar
docker-push-sidecar: ## Push docker image with the manager.
docker push ${SIDECAR_IMG}


##@ Release

RELEASE_DIR ?= out
Expand All @@ -108,13 +119,22 @@ endif
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -

.PHONY: install-certs
install-certs: manifests kustomize ## Install certs
$(KUSTOMIZE) build config/certmanager | kubectl apply -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: uninstall-certs
uninstall-certs: manifests kustomize ## Uninstall certs
$(KUSTOMIZE) build config/certmanager | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image frr-exporter=${SIDECAR_IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -

.PHONY: undeploy
Expand Down
75 changes: 65 additions & 10 deletions cmd/frr-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/telekom/das-schiff-network-operator/pkg/frr"
"github.com/telekom/das-schiff-network-operator/pkg/monitoring"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

const (
twenty = 20
)

var (
setupLog = ctrl.Log.WithName("setup")
)

func main() {
var addr string
flag.StringVar(&addr, "listen-address", ":7082", "The address to listen on for HTTP requests.")
Expand All @@ -29,6 +35,42 @@ func main() {
flag.Parse()
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// Setup a new registry.
reg, err := setupPrometheusRegistry()
if err != nil {
log.Fatal(fmt.Errorf("prometheus registry setup error: %w", err))
}

setupLog.Info("configured Prometheus registry")

endpoint, err := setupMonitoringEndpoint()
if err != nil {
log.Fatal(fmt.Errorf("error configuring monitoring endpoint: %w", err))
}

setupLog.Info("configured monitoring endpoint")

// Expose the registered metrics and monitoring endpoint via HTTP.
mux := setupMux(reg, endpoint)

server := http.Server{
Addr: addr,
ReadHeaderTimeout: twenty * time.Second,
ReadTimeout: time.Minute,
Handler: mux,
}

setupLog.Info("created server, starting...", "Addr", server.Addr,
"ReadHeaderTimeout", server.ReadHeaderTimeout, "ReadTimeout", server.ReadTimeout)

// Run server
err = server.ListenAndServe()
if err != nil {
log.Fatal(fmt.Errorf("failed to start server: %w", err))
}
}

func setupPrometheusRegistry() (*prometheus.Registry, error) {
// Create a new registry.
reg := prometheus.NewRegistry()

Expand All @@ -42,27 +84,40 @@ func main() {
"bpf": false,
})
if err != nil {
log.Fatal(fmt.Errorf("failed to create collector %w", err))
return nil, fmt.Errorf("failed to create collector %w", err)
}
reg.MustRegister(collector)

// Expose the registered metrics via HTTP.
http.Handle("/metrics", promhttp.HandlerFor(
return reg, nil
}

func setupMux(reg *prometheus.Registry, e *monitoring.Endpoint) *http.ServeMux {
mux := e.CreateMux()
mux.Handle("/metrics", promhttp.HandlerFor(
reg,
promhttp.HandlerOpts{
// Opt into OpenMetrics to support exemplars.
EnableOpenMetrics: true,
Timeout: time.Minute,
},
))
server := http.Server{
Addr: addr,
ReadHeaderTimeout: twenty * time.Second,
ReadTimeout: time.Minute,
return mux
}

func setupMonitoringEndpoint() (*monitoring.Endpoint, error) {
clientConfig := ctrl.GetConfigOrDie()
c, err := client.New(clientConfig, client.Options{})
if err != nil {
return nil, fmt.Errorf("error creating controller-runtime client: %w", err)
}
err = server.ListenAndServe()
// Run server

setupLog.Info("loaded kubernetes config")

svcName, svcNamespace, err := monitoring.GetStatusServiceConfig()
if err != nil {
log.Fatal(fmt.Errorf("failed to start server: %w", err))
return nil, fmt.Errorf("error getting status service info: %w", err)
}
setupLog.Info("loaded status service config")

return monitoring.NewEndpoint(c, frr.NewCli(), svcName, svcNamespace), nil
}
1 change: 1 addition & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resources:
- manager.yaml
- manager_master.yaml
- service.yaml
# - namespace.yaml

generatorOptions:
Expand Down
6 changes: 6 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: STATUS_SVC_NAME
value: network-operator-status
- name: STATUS_SVC_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: frr-exporter:latest
name: frr-exporter
securityContext:
Expand Down
6 changes: 6 additions & 0 deletions config/manager/manager_master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: STATUS_SVC_NAME
value: network-operator-status
- name: STATUS_SVC_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: frr-exporter:latest
name: frr-exporter
securityContext:
Expand Down
15 changes: 15 additions & 0 deletions config/manager/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: status
namespace: system
spec:
type: ClusterIP
clusterIP: None
selector:
app.kubernetes.io/component: worker
app.kubernetes.io/name: network-operator
ports:
- protocol: TCP
port: 7083
targetPort: 7083
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ rules:
- list
- update
- watch
- apiGroups:
- ""
resources:
- pods
verbs:
- list
chdxD1 marked this conversation as resolved.
Show resolved Hide resolved
- apiGroups:
- ""
resources:
- services
verbs:
chdxD1 marked this conversation as resolved.
Show resolved Hide resolved
- get
- apiGroups:
- network.schiff.telekom.de
resources:
Expand Down
12 changes: 6 additions & 6 deletions pkg/frr/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func getVRFInfo(vrf string) (name string, isMulti bool) {
return vrf, false
}

func (frr *Cli) executeWithJSON(args []string) []byte {
func (frr *Cli) ExecuteWithJSON(args []string) []byte {
// Ensure JSON is always appended
args = append(args, "json")
return frr.execute(args)
Expand All @@ -51,7 +51,7 @@ func (frr *Cli) execute(args []string) []byte {

func (frr *Cli) ShowEVPNVNIDetail() (EVPNVniDetail, error) {
evpnInfo := EVPNVniDetail{}
data := frr.executeWithJSON([]string{
data := frr.ExecuteWithJSON([]string{
"show",
"evpn",
"vni",
Expand All @@ -66,7 +66,7 @@ func (frr *Cli) ShowEVPNVNIDetail() (EVPNVniDetail, error) {

func (frr *Cli) ShowBGPSummary(vrf string) (BGPVrfSummary, error) {
vrfName, multiVRF := getVRFInfo(vrf)
data := frr.executeWithJSON([]string{
data := frr.ExecuteWithJSON([]string{
"show",
"bgp",
"vrf",
Expand All @@ -93,7 +93,7 @@ func (frr *Cli) ShowBGPSummary(vrf string) (BGPVrfSummary, error) {

func (frr *Cli) showVRFVnis() (VrfVni, error) {
vrfInfo := VrfVni{}
vrfVniData := frr.executeWithJSON([]string{
vrfVniData := frr.ExecuteWithJSON([]string{
"show",
"vrf",
"vni",
Expand Down Expand Up @@ -204,15 +204,15 @@ func (frr *Cli) ShowVRFs(vrfName string) (VrfVni, error) {
}

func (frr *Cli) getDualStackRouteSummaries(vrf string) (routeSummariesV4, routeSummariesV6 RouteSummaries, err error) {
dataV4 := frr.executeWithJSON([]string{
dataV4 := frr.ExecuteWithJSON([]string{
"show",
"ip",
"route",
"vrf",
vrf,
"summary",
})
dataV6 := frr.executeWithJSON([]string{
dataV6 := frr.ExecuteWithJSON([]string{
"show",
"ipv6",
"route",
Expand Down
Loading