Skip to content

Commit c890e84

Browse files
committed
feat(cmd): add profiling option to olm and catalog commands
1 parent a5d1e4b commit c890e84

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

cmd/catalog/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import (
1010
"time"
1111

1212
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
13-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
14-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
1513
"github.com/prometheus/client_golang/prometheus/promhttp"
1614
log "github.com/sirupsen/logrus"
1715
v1 "k8s.io/api/core/v1"
1816
utilclock "k8s.io/apimachinery/pkg/util/clock"
1917
"k8s.io/client-go/tools/clientcmd"
2018

2119
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/catalog"
20+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
21+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
22+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/profile"
2223
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
2324
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
2425
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
@@ -61,6 +62,9 @@ var (
6162

6263
tlsCertPath = flag.String(
6364
"tls-cert", "", "Path to use for certificate key (requires tls-key)")
65+
66+
profiling = flag.Bool(
67+
"profiling", false, "serve profiling data (on port 8080)")
6468
)
6569

6670
func init() {
@@ -114,6 +118,13 @@ func main() {
114118
healthMux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
115119
w.WriteHeader(http.StatusOK)
116120
})
121+
122+
// Serve profiling if enabled
123+
if *profiling {
124+
logger.Infof("profiling enabled")
125+
profile.RegisterHandlers(healthMux)
126+
}
127+
117128
go http.ListenAndServe(":8080", healthMux)
118129

119130
metricsMux := http.NewServeMux()

cmd/olm/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
13-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
1413
"github.com/prometheus/client_golang/prometheus/promhttp"
1514
log "github.com/sirupsen/logrus"
1615
v1 "k8s.io/api/core/v1"
@@ -19,6 +18,8 @@ import (
1918
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client"
2019
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/operators/olm"
2120
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
21+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorstatus"
22+
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/profile"
2223
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/signals"
2324
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
2425
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
@@ -59,6 +60,9 @@ var (
5960

6061
tlsCertPath = flag.String(
6162
"tls-cert", "", "Path to use for certificate key (requires tls-key)")
63+
64+
profiling = flag.Bool(
65+
"profiling", false, "serve profiling data (on port 8080)")
6266
)
6367

6468
func init() {
@@ -114,6 +118,13 @@ func main() {
114118
healthMux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
115119
w.WriteHeader(http.StatusOK)
116120
})
121+
122+
// Serve profiling if enabled
123+
if *profiling {
124+
logger.Infof("profiling enabled")
125+
profile.RegisterHandlers(healthMux)
126+
}
127+
117128
go func() {
118129
err := http.ListenAndServe(":8080", healthMux)
119130
if err != nil {

0 commit comments

Comments
 (0)