Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 128 additions & 16 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 4 additions & 17 deletions cmd/activator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ import (
clientset "github.com/knative/serving/pkg/client/clientset/versioned"
"github.com/knative/serving/pkg/http/h2c"
"github.com/knative/serving/pkg/logging"
"github.com/knative/serving/pkg/metrics"
"github.com/knative/serving/pkg/system"
"go.opencensus.io/exporter/prometheus"
"go.opencensus.io/stats/view"
"go.uber.org/zap"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -50,6 +49,7 @@ import (
const (
maxUploadBytes = 32e6 // 32MB - same as app engine
logLevelKey = "activator"
component = "activator"
Comment thread
akyyy marked this conversation as resolved.
Resolved

maxRetries = 18 // the sum of all retries would add up to 1 minute
minRetryInterval = 100 * time.Millisecond
Expand Down Expand Up @@ -115,14 +115,6 @@ func main() {
logger.Fatal("Error building serving clientset", zap.Error(err))
}

logger.Info("Initializing OpenCensus Prometheus exporter.")
promExporter, err := prometheus.NewExporter(prometheus.Options{Namespace: "activator"})
if err != nil {
logger.Fatal("Failed to create the Prometheus exporter", zap.Error(err))
}
view.RegisterExporter(promExporter)
view.SetReportingPeriod(10 * time.Second)

reporter, err := activator.NewStatsReporter()
if err != nil {
logger.Fatal("Failed to create stats reporter", zap.Error(err))
Expand Down Expand Up @@ -179,16 +171,11 @@ func main() {
// Watch the logging config map and dynamically update logging levels.
configMapWatcher := configmap.NewInformedWatcher(kubeClient, system.Namespace)
configMapWatcher.Watch(logging.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, logLevelKey))
// Watch the observability config map and dynamically update metrics exporter.
configMapWatcher.Watch(metrics.ObservabilityConfigName, metrics.UpdateExporterFromConfigMap(component, logger))
if err = configMapWatcher.Start(stopCh); err != nil {
logger.Fatalf("failed to start configuration manager: %v", err)
}

// Start the endpoint for Prometheus scraping
go func() {
mux := http.NewServeMux()
mux.Handle("/metrics", promExporter)
http.ListenAndServe(":9090", mux)
}()

h2c.ListenAndServe(":8080", ah)
}
21 changes: 4 additions & 17 deletions cmd/autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"flag"
"log"
"net/http"
"time"

"github.com/knative/pkg/configmap"
Expand All @@ -31,11 +30,10 @@ import (
clientset "github.com/knative/serving/pkg/client/clientset/versioned"
informers "github.com/knative/serving/pkg/client/informers/externalversions"
"github.com/knative/serving/pkg/logging"
"github.com/knative/serving/pkg/metrics"
"github.com/knative/serving/pkg/reconciler"
"github.com/knative/serving/pkg/reconciler/v1alpha1/autoscaling"
"github.com/knative/serving/pkg/system"
"go.opencensus.io/exporter/prometheus"
"go.opencensus.io/stats/view"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"k8s.io/apimachinery/pkg/util/wait"
Expand All @@ -54,6 +52,7 @@ const (
statsServerAddr = ":8080"
statsBufferLen = 1000
logLevelKey = "autoscaler"
component = "autoscaler"
)

var (
Expand Down Expand Up @@ -93,7 +92,8 @@ func main() {
// Watch the logging config map and dynamically update logging levels.
configMapWatcher := configmap.NewInformedWatcher(kubeClientSet, system.Namespace)
configMapWatcher.Watch(logging.ConfigName, logging.UpdateLevelFromConfigMap(logger, atomicLevel, logLevelKey))

// Watch the observability config map and dynamically update metrics exporter.
configMapWatcher.Watch(metrics.ObservabilityConfigName, metrics.UpdateExporterFromConfigMap(component, logger))
// This is based on how Kubernetes sets up its scale client based on discovery:
// https://github.com/kubernetes/kubernetes/blob/94c2c6c84/cmd/kube-controller-manager/app/autoscaling.go#L75-L81
restMapper := buildRESTMapper(kubeClientSet, stopCh)
Expand Down Expand Up @@ -159,19 +159,6 @@ func main() {
return ctl.Run(controllerThreads, stopCh)
})

// Setup the metrics to flow to Prometheus.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this started implicitly by importing "metrics" above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.Info("Initializing OpenCensus Prometheus exporter.")
promExporter, err := prometheus.NewExporter(prometheus.Options{Namespace: "autoscaler"})
if err != nil {
logger.Fatal("Failed to create the Prometheus exporter.", zap.Error(err))
}
view.RegisterExporter(promExporter)
view.SetReportingPeriod(time.Second * 10)
go func() {
http.Handle("/metrics", promExporter)
http.ListenAndServe(":9090", nil)
}()

statsCh := make(chan *autoscaler.StatMessage, statsBufferLen)

statsServer := statserver.New(statsServerAddr, statsCh, logger)
Expand Down
5 changes: 5 additions & 0 deletions config/activator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ spec:
volumeMounts:
- name: config-logging
mountPath: /etc/config-logging
- name: config-observability
mountPath: /etc/config-observability
volumes:
- name: config-logging
configMap:
name: config-logging
- name: config-observability
configMap:
name: config-observability
Loading