Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Gopkg.lock

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

2 changes: 2 additions & 0 deletions cmd/ela-autoscaler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ go_library(
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/gorilla/websocket:go_default_library",
"//vendor/github.com/josephburnett/k8sflag/pkg/k8sflag:go_default_library",
"//vendor/go.opencensus.io/exporter/prometheus:go_default_library",
"//vendor/go.opencensus.io/stats/view:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
Expand Down
40 changes: 36 additions & 4 deletions cmd/ela-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
"os"
"time"

"go.opencensus.io/exporter/prometheus"
"go.opencensus.io/stats/view"

"github.com/elafros/elafros/pkg/apis/ela/v1alpha1"
ela_autoscaler "github.com/elafros/elafros/pkg/autoscaler"
clientset "github.com/elafros/elafros/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -54,8 +57,10 @@ var (
kubeClient *kubernetes.Clientset
statChan = make(chan ela_autoscaler.Stat, statBufferSize)
scaleChan = make(chan int32, scaleBufferSize)
statsReporter ela_autoscaler.StatsReporter
elaNamespace string
elaDeployment string
elaConfig string
elaRevision string
elaAutoscalerPort string

Expand All @@ -75,8 +80,14 @@ func init() {
}
glog.Infof("ELA_DEPLOYMENT=%v", elaDeployment)

elaConfig = os.Getenv("ELA_CONFIGURATION")
if elaConfig == "" {
glog.Fatal("No ELA_CONFIGURATION provided.")
}
glog.Infof("ELA_CONFIGURATION=%v", elaConfig)

elaRevision = os.Getenv("ELA_REVISION")
if elaDeployment == "" {
if elaRevision == "" {
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.

Thanks!

glog.Fatal("No ELA_REVISION provided.")
}
glog.Infof("ELA_REVISION=%v", elaRevision)
Expand All @@ -96,7 +107,7 @@ func autoscaler() {
PanicWindow: k8sflag.Duration("autoscale.panic-window", nil, k8sflag.Required),
ScaleToZeroThreshold: k8sflag.Duration("autoscale.scale-to-zero-threshold", nil, k8sflag.Required, k8sflag.Dynamic),
}
a := ela_autoscaler.NewAutoscaler(config)
a := ela_autoscaler.NewAutoscaler(config, statsReporter)
ticker := time.NewTicker(2 * time.Second)

for {
Expand Down Expand Up @@ -158,6 +169,10 @@ func scaleTo(podCount int32) {
deployment.Status.Replicas,
deployment.Status.AvailableReplicas,
deployment.Status.ReadyReplicas)
statsReporter.Report(ela_autoscaler.DesiredPodCountM, (int64)(podCount))
statsReporter.Report(ela_autoscaler.RequestedPodCountM, (int64)(deployment.Status.Replicas))
statsReporter.Report(ela_autoscaler.ActualPodCountM, (int64)(deployment.Status.ReadyReplicas))

if *deployment.Spec.Replicas == podCount {
return
}
Expand Down Expand Up @@ -229,8 +244,25 @@ func main() {
glog.Fatal(err)
}
elaClient = ec

exporter, err := prometheus.NewExporter(prometheus.Options{Namespace: "autoscaler"})
if err != nil {
glog.Fatal(err)
}
view.RegisterExporter(exporter)
view.SetReportingPeriod(1 * time.Second)

reporter, err := ela_autoscaler.NewStatsReporter(elaNamespace, elaConfig, elaRevision)
if err != nil {
glog.Fatal(err)
}
statsReporter = reporter

go autoscaler()
go scaleSerializer()
http.HandleFunc("/", handler)
http.ListenAndServe(":"+elaAutoscalerPort, nil)

mux := http.NewServeMux()
mux.HandleFunc("/", handler)
mux.Handle("/metrics", exporter)
http.ListenAndServe(":"+elaAutoscalerPort, mux)
}
Loading