knative.dev/pkg@v0.0.0-20260602142205-ac97e43f6622/observability/runtime/k8s/pprof.go (about)

     1  /*
     2  Copyright 2025 The Knative Authors
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package sharedmain
    18  
    19  import (
    20  	"go.uber.org/zap"
    21  	corev1 "k8s.io/api/core/v1"
    22  	"knative.dev/pkg/observability/runtime"
    23  )
    24  
    25  type ProfilingServer struct {
    26  	*runtime.ProfilingServer
    27  	log *zap.SugaredLogger
    28  }
    29  
    30  func NewProfilingServer(logger *zap.SugaredLogger) *ProfilingServer {
    31  	s := runtime.NewProfilingServer()
    32  
    33  	return &ProfilingServer{
    34  		ProfilingServer: s,
    35  		log:             logger,
    36  	}
    37  }
    38  
    39  func (s *ProfilingServer) UpdateFromConfigMap(cm *corev1.ConfigMap) {
    40  	cfg, err := runtime.NewFromMap(cm.Data)
    41  	if err != nil {
    42  		s.log.Errorw("Failed to update the profiling flag", zap.Error(err))
    43  		return
    44  	}
    45  	s.UpdateFromConfig(cfg)
    46  }
    47  
    48  func (s *ProfilingServer) UpdateFromConfig(cfg runtime.Config) {
    49  	enabled := cfg.ProfilingEnabled()
    50  	if s.ProfilingServer.SetEnabled(enabled) != enabled {
    51  		s.log.Info("Profiling enabled: ", enabled)
    52  	}
    53  }