Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
23 changes: 15 additions & 8 deletions controllers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"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 @@ -44,7 +45,6 @@ import (
"github.com/kptdev/porch/controllers/packagevariants/pkg/controllers/packagevariant"
"github.com/kptdev/porch/controllers/packagevariantsets/pkg/controllers/packagevariantset"
"github.com/kptdev/porch/controllers/repositories/pkg/controllers/repository"
porchotel "github.com/kptdev/porch/internal/otel"
"github.com/kptdev/porch/pkg/cache/contentcache"
"github.com/kptdev/porch/pkg/controllerrestmapper"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -59,6 +59,7 @@ import (
porchv1alpha2 "github.com/kptdev/porch/api/porch/v1alpha2"
configapi "github.com/kptdev/porch/api/porchconfig/v1alpha1"
porchinternal "github.com/kptdev/porch/internal/api/porchinternal/v1alpha1"
"github.com/kptdev/porch/internal/telemetry"
//+kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -123,7 +124,18 @@ func run(ctx context.Context) error {
return err
}

mgr, err := newManager(ctx, scheme)
otel.SetLogger(klog.NewKlogr())
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 := newManager(scheme)
if err != nil {
return err
}
Expand Down Expand Up @@ -189,7 +201,7 @@ func initScheme() (*runtime.Scheme, error) {

// --- Manager ---

func newManager(ctx context.Context, scheme *runtime.Scheme) (ctrl.Manager, error) {
func newManager(scheme *runtime.Scheme) (ctrl.Manager, error) {
config := textlogger.NewConfig(
textlogger.Verbosity(4),
textlogger.Output(os.Stdout),
Expand All @@ -202,11 +214,6 @@ func newManager(ctx context.Context, scheme *runtime.Scheme) (ctrl.Manager, erro
return otelhttp.NewTransport(rt)
}

otel.SetLogger(klog.NewKlogr())
if err := porchotel.SetupOpenTelemetry(ctx); err != nil {
return nil, fmt.Errorf("error setting up OpenTelemetry: %w", err)
}

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
Expand Down
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']
Comment thread
JamesMcDermott marked this conversation as resolved.
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