Skip to content

Commit e073230

Browse files
Address reviews
1 parent 188e4a3 commit e073230

24 files changed

Lines changed: 416 additions & 529 deletions

controllers/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ func newManager(scheme *runtime.Scheme) (ctrl.Manager, error) {
214214

215215
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
216216
Scheme: scheme,
217+
// Disable controller-runtime's default :8080 /metrics listener. Port 8080 is reserved for
218+
// optional pprof (PORCH_PPROF_PORT); controller-runtime metrics are exposed on :9464 via OpenTelemetry.
217219
Metrics: metricsserver.Options{
218220
BindAddress: "0",
219221
},

deployments/metrics/pyroscope-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2026 The Nephio Authors
1+
# Copyright 2026 The kpt Authors
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

deployments/porch/2-function-runner.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ spec:
6262
value: none
6363
- name: OTEL_SERVICE_NAME
6464
value: porch-function-runner
65-
- name: PORCH_PPROF_PORT
66-
value: "8080"
6765
ports:
6866
- containerPort: 9445
6967
- containerPort: 9464

deployments/porch/3-porch-server.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ spec:
5454
memory: 256Mi
5555
cpu: 250m
5656
limits:
57-
memory: 2Gi
57+
memory: 512Mi
5858
volumeMounts:
5959
- mountPath: /cache
6060
name: cache-volume
@@ -82,8 +82,6 @@ spec:
8282
value: "9464" # Default value, showing for visibility
8383
- name: OTEL_TRACES_EXPORTER
8484
value: none
85-
- name: PORCH_PPROF_PORT
86-
value: "8080"
8785
args:
8886
- --function-runner=function-runner:9445
8987
- --cache-directory=/cache

deployments/porch/9-controllers.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ spec:
7272
value: "9464" # Default value, showing for visibility
7373
- name: OTEL_TRACES_EXPORTER
7474
value: none
75-
- name: PORCH_PPROF_PORT
76-
value: "8080"
7775
envFrom:
7876
- configMapRef:
7977
name: porch-db-config

deployments/porch/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ make deployment-config
3939
- `IMAGE_REPO`: Set image repository (default: `ghcr.io/kptdev`)
4040
- `ENABLED_RECONCILERS`: Comma-separated list of reconcilers (default: `packagevariants,packagevariantsets,repositories`)
4141
- `FN_RUNNER_WARM_UP_POD_CACHE`: Enable/disable pod cache warm-up (default: `true`)
42+
- `PORCH_GHCR_PREFIX_URL`: KRM function catalog registry prefix (from `.env` or environment). Applied to porch-server (`--default-image-prefix`), function-runner (`--default-image-prefix`), and porch-controllers (`DEFAULT_IMAGE_PREFIX`) for all `make run-in-kind*` targets that use `deployment-config`.
4243

4344
Examples:
4445

func/server/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ func buildFnConfigReconciler(o *options, scheme *runtime.Scheme) (*reconciler.Fu
245245
mgr, err := ctrl.NewManager(restCfg, ctrl.Options{
246246
Scheme: scheme,
247247
Cache: cacheOpts,
248+
// Disable controller-runtime's default :8080 /metrics listener. Port 8080 is reserved for
249+
// optional pprof (PORCH_PPROF_PORT); controller-runtime metrics are exposed on :9464 via OpenTelemetry.
248250
Metrics: metricsserver.Options{
249251
BindAddress: "0",
250252
},

internal/telemetry/metrics.go

Lines changed: 22 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ package telemetry
1616

1717
import (
1818
"context"
19-
"fmt"
2019
"time"
2120

21+
"github.com/kptdev/porch/api/porch/v1alpha1"
22+
"github.com/kptdev/porch/api/porch/v1alpha2"
2223
"github.com/kptdev/porch/pkg/repository"
2324
"go.opentelemetry.io/otel"
2425
"go.opentelemetry.io/otel/attribute"
@@ -30,30 +31,21 @@ import (
3031
const meterName = "github.com/kptdev/porch"
3132

3233
const (
33-
APIVersionV1Alpha1 = "v1alpha1"
34-
APIVersionV1Alpha2 = "v1alpha2"
35-
ControllerUser = "packagerevision-controller"
34+
ControllerUser = "packagerevision-controller"
3635

3736
ResourcePackageRevision = "PackageRevision"
3837
ResourcePackageRevisionResources = "PackageRevisionResources"
3938
ResourceExternalRepo = "ExternalRepo"
4039
)
4140

4241
var (
42+
APIVersionV1Alpha1 = v1alpha1.SchemeGroupVersion.Version
43+
APIVersionV1Alpha2 = v1alpha2.SchemeGroupVersion.Version
44+
4345
apiCallDurationSeconds metric.Float64Histogram
44-
RequestsTotal metric.Float64Counter
46+
requestsTotal metric.Float64Counter
4547
prResourceSizeHistogram metric.Int64Histogram
4648
prResourceSizeGauge metric.Int64Gauge
47-
48-
// Performance tests related vars
49-
perfOperationDuration metric.Float64Histogram
50-
perfOperationCounter metric.Float64Counter
51-
perfRepositoryCounter metric.Float64Counter
52-
perfPackageCounter metric.Float64Counter
53-
perfPackageRevisionCounter metric.Float64Counter
54-
perfLifecycleTransitionDuration metric.Float64Histogram
55-
perfTestRunInfoGauge metric.Float64Gauge
56-
perfActiveOperations metric.Float64UpDownCounter
5749
)
5850

5951
func InitMetrics() (err error) {
@@ -69,15 +61,17 @@ func InitMetrics() (err error) {
6961
),
7062
)
7163
if err != nil {
72-
panic(fmt.Sprintf("failed to create porch_api_call_duration_seconds: %v", err))
64+
klog.Errorf("failed to create porch_api_call_duration_seconds: %v", err)
65+
return
7366
}
7467

75-
RequestsTotal, err = m.Float64Counter(
68+
requestsTotal, err = m.Float64Counter(
7669
"porch_api_requests_by_user",
7770
metric.WithDescription("Total number of requests tracked by BurstCounter, broken down by resource, operation, and user."),
7871
)
7972
if err != nil {
80-
panic(fmt.Sprintf("failed to create porch_api_requests_by_user: %v", err))
73+
klog.Errorf("failed to create porch_api_requests_by_user: %v", err)
74+
return
8175
}
8276

8377
prResourceSizeHistogram, err = m.Int64Histogram(
@@ -101,81 +95,13 @@ func InitMetrics() (err error) {
10195
return
10296
}
10397

104-
// Performance test related metrics
105-
perfOperationDuration, err = m.Float64Histogram(
106-
"porch_perf_operation_duration_seconds",
107-
metric.WithDescription("Duration of Porch performance test operations in seconds"),
108-
metric.WithUnit("s"),
109-
metric.WithExplicitBucketBoundaries(0.01, 0.05, 0.1, 0.5, 1, 2, 5, 10, 30, 60, 120),
110-
)
111-
if err != nil {
112-
panic(fmt.Sprintf("failed to create porch_perf_operation_duration_seconds: %v", err))
113-
}
114-
115-
perfOperationCounter, err = m.Float64Counter(
116-
"porch_perf_operations_total",
117-
metric.WithDescription("Total number of Porch performance test operations"),
118-
)
119-
if err != nil {
120-
panic(fmt.Sprintf("failed to create porch_perf_operations_total: %v", err))
121-
}
122-
123-
perfRepositoryCounter, err = m.Float64Counter(
124-
"porch_perf_repositories_created_total",
125-
metric.WithDescription("Total number of repositories created in performance tests"),
126-
)
127-
if err != nil {
128-
panic(fmt.Sprintf("failed to create porch_perf_repositories_created_total: %v", err))
129-
}
130-
131-
perfPackageCounter, err = m.Float64Counter(
132-
"porch_perf_packages_created_total",
133-
metric.WithDescription("Total number of packages created in performance tests"),
134-
)
135-
if err != nil {
136-
panic(fmt.Sprintf("failed to create porch_perf_packages_created_total: %v", err))
137-
}
138-
139-
perfPackageRevisionCounter, err = m.Float64Counter(
140-
"porch_perf_package_revisions_total",
141-
metric.WithDescription("Total number of package revisions created in performance tests"),
142-
)
143-
if err != nil {
144-
panic(fmt.Sprintf("failed to create porch_perf_package_revisions_total: %v", err))
145-
}
146-
147-
perfLifecycleTransitionDuration, err = m.Float64Histogram(
148-
"porch_perf_lifecycle_transition_duration_seconds",
149-
metric.WithDescription("Duration of package lifecycle transitions in seconds"),
150-
metric.WithUnit("s"),
151-
metric.WithExplicitBucketBoundaries(0.1, 0.5, 1, 2, 5, 10, 30, 60),
152-
)
153-
if err != nil {
154-
panic(fmt.Sprintf("failed to create porch_perf_lifecycle_transition_duration_seconds: %v", err))
155-
}
156-
157-
perfTestRunInfoGauge, err = m.Float64Gauge(
158-
"porch_perf_test_run_info",
159-
metric.WithDescription("Information about the current performance test run"),
160-
)
161-
if err != nil {
162-
panic(fmt.Sprintf("failed to create porch_perf_test_run_info: %v", err))
163-
}
164-
165-
perfActiveOperations, err = m.Float64UpDownCounter(
166-
"porch_perf_active_operations",
167-
metric.WithDescription("Number of currently active operations"),
168-
)
169-
if err != nil {
170-
panic(fmt.Sprintf("failed to create porch_perf_active_operations: %v", err))
171-
}
172-
17398
return nil
17499
}
175100

176101
// Porch server and function runner metric recording functions
177102
func RecordAPICallDuration(resource, verb, apiVersion string, durationSeconds float64) {
178103
if apiCallDurationSeconds == nil {
104+
klog.Warning("apiCallDurationSeconds is nil - was InitMetrics() called?")
179105
return
180106
}
181107
apiCallDurationSeconds.Record(context.Background(), durationSeconds,
@@ -188,14 +114,16 @@ func RecordAPICallDuration(resource, verb, apiVersion string, durationSeconds fl
188114
}
189115

190116
func RecordRequestCount(ctx context.Context, resource, op, apiVersion string) {
191-
if RequestsTotal == nil {
117+
if requestsTotal == nil {
118+
klog.Warning("requestsTotal is nil - was InitMetrics() called?")
192119
return
193120
}
194121
recordRequestCount(resource, op, apiVersion, getK8sUserName(ctx))
195122
}
196123

197124
func RecordControllerRequestCount(resource, op, apiVersion string) {
198-
if RequestsTotal == nil {
125+
if requestsTotal == nil {
126+
klog.Warning("requestsTotal is nil - was InitMetrics() called?")
199127
return
200128
}
201129
recordRequestCount(resource, op, apiVersion, ControllerUser)
@@ -208,7 +136,7 @@ func RecordControllerOperation(resource, verb string, start time.Time) {
208136
}
209137

210138
func recordRequestCount(resource, op, apiVersion, user string) {
211-
RequestsTotal.Add(context.Background(), 1,
139+
requestsTotal.Add(context.Background(), 1,
212140
metric.WithAttributes(
213141
attribute.String("resource", resource),
214142
attribute.String("op", op),
@@ -226,6 +154,7 @@ func RecordExternalRepoOperation(ctx context.Context, op string, start time.Time
226154

227155
func recordExternalRepoDuration(op string, durationSeconds float64) {
228156
if apiCallDurationSeconds == nil {
157+
klog.Warning("apiCallDurationSeconds is nil - was InitMetrics() called?")
229158
return
230159
}
231160
apiCallDurationSeconds.Record(context.Background(), durationSeconds,
@@ -237,10 +166,11 @@ func recordExternalRepoDuration(op string, durationSeconds float64) {
237166
}
238167

239168
func RecordExternalRepoRequestCount(ctx context.Context, op string) {
240-
if RequestsTotal == nil {
169+
if requestsTotal == nil {
170+
klog.Warning("requestsTotal is nil - was InitMetrics() called?")
241171
return
242172
}
243-
RequestsTotal.Add(context.Background(), 1,
173+
requestsTotal.Add(context.Background(), 1,
244174
metric.WithAttributes(
245175
attribute.String("resource", ResourceExternalRepo),
246176
attribute.String("op", op),
@@ -283,77 +213,6 @@ func RecordPackageRevisionResourcesSize(ctx context.Context, prKey repository.Pa
283213
prResourceSizeGauge.Record(ctx, resourcesSize, metric.WithAttributeSet(attributes))
284214
}
285215

286-
// Performance test metric recording functions
287-
func PerfTestRecordMetric(operation, apiVersion, repoName, pkgName string, duration time.Duration, err error) {
288-
attrs := metric.WithAttributes(
289-
attribute.String("operation", operation),
290-
attribute.String("api_version", apiVersion),
291-
attribute.String("repository", repoName),
292-
attribute.String("package", pkgName),
293-
attribute.String("status", statusLabel(err)),
294-
)
295-
ctx := context.Background()
296-
perfOperationDuration.Record(ctx, duration.Seconds(), attrs)
297-
perfOperationCounter.Add(ctx, 1, attrs)
298-
}
299-
300-
func PerfTestRecordLifecycleTransition(fromState, toState, apiVersion, repoName, pkgName string, duration time.Duration, err error) {
301-
perfLifecycleTransitionDuration.Record(context.Background(), duration.Seconds(),
302-
metric.WithAttributes(
303-
attribute.String("from_state", fromState),
304-
attribute.String("to_state", toState),
305-
attribute.String("api_version", apiVersion),
306-
attribute.String("repository", repoName),
307-
attribute.String("package", pkgName),
308-
attribute.String("status", statusLabel(err)),
309-
),
310-
)
311-
}
312-
313-
func PerfTestRecordPackageRevision(operation string, err error) {
314-
perfPackageRevisionCounter.Add(context.Background(), 1,
315-
metric.WithAttributes(
316-
attribute.String("operation", operation),
317-
attribute.String("status", statusLabel(err)),
318-
),
319-
)
320-
}
321-
322-
func PerfTestSetTestRunInfo(testName, namespace, apiVersion string, startTime time.Time) {
323-
perfTestRunInfoGauge.Record(context.Background(), 1,
324-
metric.WithAttributes(
325-
attribute.String("test_name", testName),
326-
attribute.String("namespace", namespace),
327-
attribute.String("api_version", apiVersion),
328-
attribute.String("start_time", startTime.Format(time.RFC3339)),
329-
),
330-
)
331-
}
332-
333-
func PerfTestRecordActiveOperation(operation, apiVersion string, delta float64) {
334-
perfActiveOperations.Add(context.Background(), delta,
335-
metric.WithAttributes(
336-
attribute.String("operation", operation),
337-
attribute.String("api_version", apiVersion),
338-
),
339-
)
340-
}
341-
342-
func PerfTestIncrementRepositoryCounter() {
343-
perfRepositoryCounter.Add(context.Background(), 1)
344-
}
345-
346-
func PerfTestIncrementPackageCounter() {
347-
perfPackageCounter.Add(context.Background(), 1)
348-
}
349-
350-
func statusLabel(err error) string {
351-
if err != nil {
352-
return "error"
353-
}
354-
return "success"
355-
}
356-
357216
func getK8sUserName(ctx context.Context) string {
358217
if user, ok := request.UserFrom(ctx); ok {
359218
return user.GetName()

0 commit comments

Comments
 (0)