Skip to content

Commit fb1acfb

Browse files
committed
Merge upstream/main and address PR review comments
2 parents 8f8ffab + dc863c6 commit fb1acfb

File tree

12 files changed

+40
-14
lines changed

12 files changed

+40
-14
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
@@ -28,6 +28,7 @@ This changelog keeps track of work items that have been completed and are ready
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))
3030
- **General**: Add custom placeholder pages for scale-from-zero scenarios ([#874](https://github.com/kedacore/http-add-on/issues/874))
31+
- **General**: Support profiling for KEDA components ([#4789](https://github.com/kedacore/keda/issues/4789))
3132

3233
### Improvements
3334

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/handler/placeholder.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ func NewPlaceholderHandler(k8sClient kubernetes.Interface, routingTable routing.
145145

146146
// injectPlaceholderScript injects the placeholder refresh script into a template
147147
func injectPlaceholderScript(templateContent string) string {
148+
// Check if the placeholder script is already present
149+
if strings.Contains(templateContent, placeholderScript) {
150+
// Return the original content if the script is already present
151+
return templateContent
152+
}
153+
148154
lowerContent := strings.ToLower(templateContent)
149155

150156
// Look for </body> tag (case-insensitive)
@@ -247,13 +253,13 @@ func (h *PlaceholderHandler) getTemplate(ctx context.Context, hso *v1alpha1.HTTP
247253
}
248254
h.cacheMutex.RUnlock()
249255

256+
h.cacheMutex.Lock()
250257
injectedContent := injectPlaceholderScript(config.Content)
251258
tmpl, err := template.New("inline").Parse(injectedContent)
252259
if err != nil {
260+
h.cacheMutex.Unlock()
253261
return nil, err
254262
}
255-
256-
h.cacheMutex.Lock()
257263
h.templateCache[cacheKey] = &cacheEntry{
258264
template: tmpl,
259265
hsoGeneration: hso.Generation,
@@ -278,23 +284,24 @@ func (h *PlaceholderHandler) getTemplate(ctx context.Context, hso *v1alpha1.HTTP
278284
}
279285
h.cacheMutex.RUnlock()
280286

287+
h.cacheMutex.Lock()
281288
key := config.ContentConfigMapKey
282289
if key == "" {
283290
key = "template.html"
284291
}
285292

286293
content, ok := cm.Data[key]
287294
if !ok {
295+
h.cacheMutex.Unlock()
288296
return nil, fmt.Errorf("key %s not found in ConfigMap %s", key, config.ContentConfigMap)
289297
}
290298

291299
injectedContent := injectPlaceholderScript(content)
292300
tmpl, err := template.New("configmap").Parse(injectedContent)
293301
if err != nil {
302+
h.cacheMutex.Unlock()
294303
return nil, err
295304
}
296-
297-
h.cacheMutex.Lock()
298305
h.templateCache[cacheKey] = &cacheEntry{
299306
template: tmpl,
300307
hsoGeneration: hso.Generation,

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

0 commit comments

Comments
 (0)