mirror of
https://github.com/coreos/prometheus-operator.git
synced 2026-02-05 15:46:31 +01:00
feat: add automatic GOMAXPROCS to admission webhook
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/goruntime"
|
||||
logging "github.com/prometheus-operator/prometheus-operator/internal/log"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/admission"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/server"
|
||||
@@ -60,6 +61,8 @@ func main() {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
|
||||
goruntime.SetMaxProcs(logger)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
wg, ctx := errgroup.WithContext(ctx)
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
@@ -34,7 +33,6 @@ import (
|
||||
versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/prometheus/common/version"
|
||||
"go.uber.org/automaxprocs/maxprocs"
|
||||
"golang.org/x/sync/errgroup"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
@@ -44,6 +42,7 @@ import (
|
||||
k8sflag "k8s.io/component-base/cli/flag"
|
||||
"k8s.io/utils/ptr"
|
||||
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/goruntime"
|
||||
logging "github.com/prometheus-operator/prometheus-operator/internal/log"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/admission"
|
||||
alertmanagercontroller "github.com/prometheus-operator/prometheus-operator/pkg/alertmanager"
|
||||
@@ -195,13 +194,6 @@ func run(fs *flag.FlagSet) int {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
|
||||
l := func(format string, a ...interface{}) {
|
||||
level.Info(logger).Log("component", "automaxprocs", "msg", fmt.Sprintf(strings.TrimPrefix(format, "maxprocs: "), a...))
|
||||
}
|
||||
if _, err := maxprocs.Set(maxprocs.Logger(l)); err != nil {
|
||||
level.Warn(logger).Log("msg", "Failed to set GOMAXPROCS automatically", "err", err)
|
||||
}
|
||||
|
||||
gates, err := operator.ValidateFeatureGates(featureGates)
|
||||
if err != nil {
|
||||
level.Error(logger).Log(
|
||||
@@ -213,6 +205,7 @@ func run(fs *flag.FlagSet) int {
|
||||
level.Info(logger).Log("msg", "Starting Prometheus Operator", "version", version.Info())
|
||||
level.Info(logger).Log("build_context", version.BuildContext())
|
||||
level.Info(logger).Log("feature_gates", gates)
|
||||
goruntime.SetMaxProcs(logger)
|
||||
|
||||
if len(cfg.Namespaces.AllowList) > 0 && len(cfg.Namespaces.DenyList) > 0 {
|
||||
level.Error(logger).Log(
|
||||
|
||||
@@ -37,8 +37,8 @@ import (
|
||||
"github.com/prometheus/common/version"
|
||||
"github.com/prometheus/exporter-toolkit/web"
|
||||
"github.com/thanos-io/thanos/pkg/reloader"
|
||||
"go.uber.org/automaxprocs/maxprocs"
|
||||
|
||||
"github.com/prometheus-operator/prometheus-operator/internal/goruntime"
|
||||
logging "github.com/prometheus-operator/prometheus-operator/internal/log"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/operator"
|
||||
"github.com/prometheus-operator/prometheus-operator/pkg/versionutil"
|
||||
@@ -123,13 +123,6 @@ func main() {
|
||||
stdlog.Fatal(err)
|
||||
}
|
||||
|
||||
l := func(format string, a ...interface{}) {
|
||||
level.Info(logger).Log("component", "automaxprocs", "msg", fmt.Sprintf(strings.TrimPrefix(format, "maxprocs: "), a...))
|
||||
}
|
||||
if _, err := maxprocs.Set(maxprocs.Logger(l)); err != nil {
|
||||
level.Warn(logger).Log("msg", "Failed to set GOMAXPROCS automatically", "err", err)
|
||||
}
|
||||
|
||||
err = web.Validate(*webConfig)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Unable to validate web configuration file", "err", err)
|
||||
@@ -144,6 +137,7 @@ func main() {
|
||||
|
||||
level.Info(logger).Log("msg", "Starting prometheus-config-reloader", "version", version.Info())
|
||||
level.Info(logger).Log("build_context", version.BuildContext())
|
||||
goruntime.SetMaxProcs(logger)
|
||||
|
||||
r := prometheus.NewRegistry()
|
||||
r.MustRegister(
|
||||
|
||||
34
internal/goruntime/cpu.go
Normal file
34
internal/goruntime/cpu.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2024 The prometheus-operator Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package goruntime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/go-kit/log/level"
|
||||
"go.uber.org/automaxprocs/maxprocs"
|
||||
)
|
||||
|
||||
func SetMaxProcs(logger log.Logger) {
|
||||
l := func(format string, a ...interface{}) {
|
||||
level.Info(logger).Log("msg", fmt.Sprintf(strings.TrimPrefix(format, "maxprocs: "), a...))
|
||||
}
|
||||
|
||||
if _, err := maxprocs.Set(maxprocs.Logger(l)); err != nil {
|
||||
level.Warn(logger).Log("msg", "Failed to set GOMAXPROCS automatically", "err", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user