Skip to content
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
13 changes: 10 additions & 3 deletions cmd/porch/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The kpt Authors
// Copyright 2022, 2026 The kpt Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,9 @@ package main

import (
"os"
"time"

porchotel "github.com/kptdev/porch/internal/otel"
"github.com/kptdev/porch/internal/telemetry"
"github.com/kptdev/porch/pkg/cmd/server"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/component-base/cli"
Expand All @@ -34,12 +35,18 @@ func main() {
func run() int {
log.SetLogger(zap.New(zap.UseDevMode(true)))
ctx := genericapiserver.SetupSignalContext()
err := porchotel.SetupOpenTelemetry(ctx)
otelResources, err := telemetry.SetupOpenTelemetry(ctx)
if err != nil {
genericapiserver.RequestShutdown()
klog.Errorf("%v\n", err)
return 1
}
defer func() {
if err := otelResources.ShutdownWithTimeout(10 * time.Second); err != nil {
klog.Warningf("failed to gracefully shutdown OpenTelemetry: %v", err)
}
}()

options := server.NewPorchServerOptions(os.Stdout, os.Stderr)
cmd := server.NewCommandStartPorchServer(ctx, options)
code := cli.Run(cmd)
Expand Down
10 changes: 8 additions & 2 deletions controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"net/http"
"os"
"strings"
"time"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
Expand All @@ -41,7 +42,7 @@
porchapi "github.com/kptdev/porch/api/porch/v1alpha1"
"github.com/kptdev/porch/controllers/packagevariants/pkg/controllers/packagevariant"
"github.com/kptdev/porch/controllers/packagevariantsets/pkg/controllers/packagevariantset"
porchotel "github.com/kptdev/porch/internal/otel"
"github.com/kptdev/porch/internal/telemetry"
"github.com/kptdev/porch/pkg/controllerrestmapper"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -86,7 +87,7 @@
}
}

func run(ctx context.Context) error {

Check failure on line 90 in controllers/main.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 19 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=kptdev_porch&issues=AZ7Q9J1sTVL8MORpImat&open=AZ7Q9J1sTVL8MORpImat&pullRequest=1052
// var metricsAddr string
// var enableLeaderElection bool
// var probeAddr string
Expand Down Expand Up @@ -158,10 +159,15 @@
}

otel.SetLogger(klog.NewKlogr())
err := porchotel.SetupOpenTelemetry(ctx)
otelResources, err := telemetry.SetupOpenTelemetry(ctx)
if err != nil {
return fmt.Errorf("error setting up OpenTelemetry: %w", err)
}
defer func() {
if shutdownErr := otelResources.ShutdownWithTimeout(10 * time.Second); shutdownErr != nil {
klog.Warningf("failed to gracefully shutdown OpenTelemetry: %v", shutdownErr)
}
}()

mgr, err := ctrl.NewManager(cfg, managerOptions)
if err != nil {
Expand Down
17 changes: 17 additions & 0 deletions deployments/function-pods/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ data:
volumeMounts:
- name: wrapper-server-tools
mountPath: /wrapper-server-tools
env:
- name: OTEL_METRICS_EXPORTER
value: prometheus
- name: OTEL_TRACES_EXPORTER
value: none
- name: OTEL_EXPORTER_PROMETHEUS_HOST
value: 0.0.0.0
- name: OTEL_EXPORTER_PROMETHEUS_PORT
value: "9464" # Default value, showing for visibility
ports:
- containerPort: 9464
name: metrics
volumes:
- name: wrapper-server-tools
emptyDir: {}
Expand All @@ -54,6 +66,11 @@ data:
- port: 9446
protocol: TCP
targetPort: 9446
name: server
- port: 9464
protocol: TCP
targetPort: 9464
name: metrics
selector:
fn.kpt.dev/image: to-be-replaced
type: ClusterIP
Expand Down
49 changes: 49 additions & 0 deletions deployments/metrics-resources/grafana-package-sizes-dashboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"annotations": { "list": [] },
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 1,
"id": null,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"description": "Total file size, in bytes, of package revisions' resources",
"fieldConfig": {
"defaults": {
"color": { "mode": "palette-classic" },
"custom": { "axisCenteredZero": false, "axisLabel": "", "axisPlacement": "auto", "drawStyle": "line", "fillOpacity": 0, "gradientMode": "none", "lineInterpolation": "linear", "lineWidth": 1, "pointSize": 5, "scaleDistribution": { "type": "linear" }, "showPoints": "auto", "spanNulls": false, "stacking": { "group": "A", "mode": "none" }, "thresholdsStyle": { "mode": "off" } },
"unit": "decbytes"
},
"overrides": []
},
"gridPos": { "h": 100, "w": 24, "x": 0, "y": 0 },
"id": 101,
"options": { "legend": { "displayMode": "list", "placement": "bottom", "showLegend": true }, "tooltip": { "mode": "multi", "sort": "none" } },
"targets": [
{
"datasource": { "type": "prometheus", "uid": "prometheus" },
"expr": "porch_package_size_bytes_total",
"legendFormat": "{{namespace}}/{{package}}/{{workspace_name}}",
"range": true,
"refId": "total-size-gauge"
}
],
"title": "PR Resource Sizes",
"type": "timeseries"
}
],
"refresh": "10s",
"schemaVersion": 38,
"style": "dark",
"tags": ["porch", "resources"],
"templating": { "list": [] },
"time": { "from": "now-1h", "to": "now" },
"timepicker": {},
"timezone": "",
"title": "Porch File-system Resources",
"uid": "porch-package-resources",
"version": 1,
"weekStart": ""
}
48 changes: 48 additions & 0 deletions deployments/metrics-resources/prometheus-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2026 The kpt Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

global:
scrape_native_histograms: true
scrape_interval: 10s
evaluation_interval: 10s
external_labels:
cluster: 'porch'

scrape_configs:
- job_name: 'porch-server'
scrape_native_histograms: true
scrape_interval: 10s
scrape_timeout: 10s
static_configs:
- targets: ['api.porch-system.svc.cluster.local:9464']
labels:
service: 'porch'

- job_name: 'porch-controllers'
scrape_native_histograms: true
scrape_interval: 10s
scrape_timeout: 10s
static_configs:
- targets: ['porch-controllers.porch-system.svc.cluster.local:9464']
labels:
service: 'porch'

- job_name: 'function-runner'
scrape_interval: 10s
scrape_timeout: 10s
static_configs:
- targets: ['function-runner.porch-system.svc.cluster.local:9464']
labels:
service: 'function-runner'
component: 'grpc-server'
149 changes: 149 additions & 0 deletions deployments/metrics/grafana-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Copyright 2026 The kpt Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana
namespace: porch-monitoring # kpt-set: ${namespace}
labels:
app: grafana
spec:
replicas: 1
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
containers:
- name: grafana
image: docker.io/grafana/grafana:latest # kpt-set: ${grafana-image}
ports:
- containerPort: 3000 # kpt-set: ${grafana-container-port}
name: http
env:
- name: GF_SECURITY_ADMIN_USER
valueFrom:
secretKeyRef:
name: grafana-admin-creds
key: GF_SECURITY_ADMIN_USER
- name: GF_SECURITY_ADMIN_PASSWORD
valueFrom:
secretKeyRef:
name: grafana-admin-creds
key: GF_SECURITY_ADMIN_PASSWORD
- name: GF_USERS_ALLOW_SIGN_UP
value: "false"
- name: GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH
value: "/var/lib/grafana/dashboards/grafana-porch-server-dashboard.json"
- name: GF_DASHBOARDS_MIN_REFRESH_INTERVAL
value: "1s"
- name: GF_SERVER_ENABLE_GZIP
value: "true"
- name: GF_DATABASE_WAL
value: "true"
livenessProbe:
httpGet:
path: /api/health
port: 3000
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
readinessProbe:
httpGet:
path: /api/health
port: 3000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
volumeMounts:
- name: grafana-storage
mountPath: /var/lib/grafana
- name: grafana-datasources
mountPath: /etc/grafana/provisioning/datasources
- name: grafana-dashboards-provider
mountPath: /etc/grafana/provisioning/dashboards
- name: grafana-dashboards
mountPath: /var/lib/grafana/dashboards
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "1"
volumes:
- name: grafana-storage
emptyDir: {}
- name: grafana-datasources
configMap:
name: grafana-datasources
- name: grafana-dashboards-provider
configMap:
name: grafana-dashboards-provider
- name: grafana-dashboards
configMap:
name: grafana-dashboards
---
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-dashboards-provider
namespace: porch-monitoring # kpt-set: ${namespace}
data:
dashboards.yaml: |
apiVersion: 1
providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: true
options:
path: /var/lib/grafana/dashboards
---
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-datasources
namespace: porch-monitoring # kpt-set: ${namespace}
data:
prometheus.yaml: |
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
uid: prometheus
url: http://prometheus:9090
isDefault: true
editable: true
---
apiVersion: v1
data:
GF_SECURITY_ADMIN_USER: cG9yY2g= # kpt-set: ${grafana-user}
GF_SECURITY_ADMIN_PASSWORD: cG9yY2g= # kpt-set: ${grafana-pw}
kind: Secret
metadata:
name: grafana-admin-creds
namespace: porch-monitoring # kpt-set: ${namespace}
labels:
app: grafana
type: Opaque
Loading
Loading