Skip to content

Commit dc863c6

Browse files
authored
Add a way to turn off the profiling for all three http add-on components (#1308)
* Add a way to turn off the profiling for all three http add-on components Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com> * linter - The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar. Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com> --------- Signed-off-by: Jirka Kremser <jiri.kremser@gmail.com>
1 parent 6a6adfb commit dc863c6

File tree

11 files changed

+29
-10
lines changed

11 files changed

+29
-10
lines changed

.github/workflows/linkinator.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ jobs:
2121
with:
2222
paths: "**/*.md"
2323
markdown: true
24+
concurrency: 1
2425
retry: true
2526
linksToSkip: "https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-interceptor, https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-operator, https://github.com/kedacore/http-add-on/pkgs/container/http-add-on-scaler,http://opentelemetry-collector.open-telemetry-system:4318,http://opentelemetry-collector.open-telemetry-system:4318/v1/traces, https://www.gnu.org/software/make/"

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ linters:
2626
- unconvert
2727
- ineffassign
2828
- staticcheck
29-
- exportloopref
29+
- copyloopvar
3030
#- depguard #https://github.com/kedacore/keda/issues/4980
3131
- dogsled
3232
- errcheck

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This changelog keeps track of work items that have been completed and are ready
2727

2828
- **General**: Add configurable tracing support to the interceptor proxy ([#1021](https://github.com/kedacore/http-add-on/pull/1021))
2929
- **General**: Allow using HSO and SO with different names ([#1293](https://github.com/kedacore/http-add-on/issues/1293))
30+
- **General**: Support profiling for KEDA components ([#4789](https://github.com/kedacore/keda/issues/4789))
3031

3132
### Improvements
3233

interceptor/config/serving.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type Serving struct {
4545
TLSCertStorePaths string `envconfig:"KEDA_HTTP_PROXY_TLS_CERT_STORE_PATHS" default:""`
4646
// TLSPort is the port that the server should serve on if TLS is enabled
4747
TLSPort int `envconfig:"KEDA_HTTP_PROXY_TLS_PORT" default:"8443"`
48+
// ProfilingAddr if not empty, pprof will be available on this address, assuming host:port here
49+
ProfilingAddr string `envconfig:"PROFILING_BIND_ADDRESS" default:""`
4850
}
4951

5052
// Parse parses standard configs using envconfig and returns a pointer to the

interceptor/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"flag"
99
"fmt"
1010
"net/http"
11+
_ "net/http/pprof"
1112
"os"
1213
"path/filepath"
1314
"runtime"
@@ -81,6 +82,7 @@ func main() {
8182
proxyPort := servingCfg.ProxyPort
8283
adminPort := servingCfg.AdminPort
8384
proxyTLSEnabled := servingCfg.ProxyTLSEnabled
85+
profilingAddr := servingCfg.ProfilingAddr
8486

8587
// setup the configured metrics collectors
8688
metrics.NewMetricsCollectors(metricsCfg)
@@ -218,6 +220,13 @@ func main() {
218220
return nil
219221
})
220222

223+
if len(profilingAddr) > 0 {
224+
eg.Go(func() error {
225+
setupLog.Info("enabling pprof for profiling", "address", profilingAddr)
226+
return http.ListenAndServe(profilingAddr, nil)
227+
})
228+
}
229+
221230
build.PrintComponentInfo(ctrl.Log, "Interceptor")
222231

223232
if err := eg.Wait(); err != nil && !errors.Is(err, context.Canceled) {

operator/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ func main() {
5757
var metricsAddr string
5858
var enableLeaderElection bool
5959
var probeAddr string
60+
var profilingAddr string
6061
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6162
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6263
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6364
"Enable leader election for controller manager. "+
6465
"Enabling this will ensure there is only one active controller manager.")
66+
flag.StringVar(&profilingAddr, "profiling-bind-address", "", "The address the profiling would be exposed on.")
6567
opts := zap.Options{
6668
Development: true,
6769
}
@@ -96,6 +98,7 @@ func main() {
9698
Metrics: server.Options{
9799
BindAddress: metricsAddr,
98100
},
101+
PprofBindAddress: profilingAddr,
99102
HealthProbeBindAddress: probeAddr,
100103
LeaderElection: enableLeaderElection,
101104
LeaderElectionID: "http-add-on.keda.sh",

pkg/k8s/endpoints_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ func TestGetEndpoints(t *testing.T) {
5757
addrLookup := map[string]*v1.EndpointAddress{}
5858
for _, subset := range endpoints.Subsets {
5959
for _, addr := range subset.Addresses {
60-
addr := addr
6160
key := fmt.Sprintf("http://%s:%s", addr.IP, svcPort)
6261
addrLookup[key] = &addr
6362
}

pkg/routing/table_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ var _ = Describe("Table", func() {
190190
defer cancel()
191191

192192
for _, httpso := range httpsoList.Items {
193-
httpso := httpso
194-
195193
key := *k8s.NamespacedNameFromObject(&httpso)
196194
t.httpScaledObjects[key] = &httpso
197195
}
@@ -216,8 +214,6 @@ var _ = Describe("Table", func() {
216214
defer cancel()
217215

218216
for _, httpso := range httpsoList.Items {
219-
httpso := httpso
220-
221217
key := *k8s.NamespacedNameFromObject(&httpso)
222218
t.httpScaledObjects[key] = &httpso
223219
}
@@ -285,8 +281,6 @@ var _ = Describe("Table", func() {
285281

286282
It("returns new memory based on HTTPSOs", func() {
287283
for _, httpso := range httpsoList.Items {
288-
httpso := httpso
289-
290284
key := *k8s.NamespacedNameFromObject(&httpso)
291285
t.httpScaledObjects[key] = &httpso
292286
}

pkg/routing/tablememory_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,6 @@ var _ = Describe("TableMemory", func() {
484484
store: iradix.New[*httpv1alpha1.HTTPScaledObject](),
485485
}
486486
for _, httpso := range httpsoList.Items {
487-
httpso := httpso
488-
489487
tm = insertTrees(tm, &httpso)
490488
}
491489

scaler/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type config struct {
3434
DeploymentCacheRsyncPeriod time.Duration `envconfig:"KEDA_HTTP_SCALER_DEPLOYMENT_INFORMER_RSYNC_PERIOD" default:"60m"`
3535
// QueueTickDuration is the duration between queue requests
3636
QueueTickDuration time.Duration `envconfig:"KEDA_HTTP_QUEUE_TICK_DURATION" default:"500ms"`
37+
// ProfilingAddr if not empty, pprof will be available on this address, assuming host:port here
38+
ProfilingAddr string `envconfig:"PROFILING_BIND_ADDRESS" default:""`
3739
}
3840

3941
func mustParseConfig() *config {

0 commit comments

Comments
 (0)