Skip to content

Commit

Permalink
attaches server profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhang.balkundi committed Jun 27, 2023
1 parent 9b9bba2 commit a1b349f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
EnablePolicyChecksFlag = "enable-policy-checks"
EnableRegExpCmdFlag = "enable-regexp-cmd"
EnableDiffMarkdownFormat = "enable-diff-markdown-format"
EnableServerProfiling = "enable-server-profiling"
GHHostnameFlag = "gh-hostname"
GHTeamAllowlistFlag = "gh-team-allowlist"
GHTokenFlag = "gh-token"
Expand Down Expand Up @@ -397,6 +398,10 @@ var boolFlags = map[string]boolFlag{
description: "Enable Atlantis to format Terraform plan output into a markdown-diff friendly format for color-coding purposes.",
defaultValue: false,
},
EnableServerProfiling: {
description: "Enables profiler",
defaultValue: false,
},
GHAllowMergeableBypassApply: {
description: "Feature flag to enable functionality to allow mergeable check to ignore apply required check",
defaultValue: false,
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/spf13/viper"
)

const atlantisVersion = "0.19.12"
const atlantisVersion = "0.19.13"

func main() {
v := viper.New()
Expand Down
20 changes: 17 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io"
"log"
"net/http"
"net/http/pprof"
"net/url"
"os"
"os/signal"
Expand All @@ -31,20 +32,18 @@ import (
"syscall"
"time"

"github.com/mitchellh/go-homedir"
cfg "github.com/gojekfarm/atlantis/server/core/config"
"github.com/gojekfarm/atlantis/server/core/config/valid"
"github.com/gojekfarm/atlantis/server/core/db"
"github.com/gojekfarm/atlantis/server/core/redis"
"github.com/gojekfarm/atlantis/server/jobs"
"github.com/gojekfarm/atlantis/server/metrics"
"github.com/gojekfarm/atlantis/server/scheduled"
"github.com/mitchellh/go-homedir"
"github.com/uber-go/tally"
"github.com/uber-go/tally/prometheus"

assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/gojekfarm/atlantis/server/controllers"
events_controllers "github.com/gojekfarm/atlantis/server/controllers/events"
"github.com/gojekfarm/atlantis/server/controllers/templates"
Expand All @@ -62,6 +61,8 @@ import (
"github.com/gojekfarm/atlantis/server/events/webhooks"
"github.com/gojekfarm/atlantis/server/logging"
"github.com/gojekfarm/atlantis/server/static"
"github.com/gorilla/mux"
"github.com/pkg/errors"
"github.com/urfave/cli"
"github.com/urfave/negroni"
)
Expand Down Expand Up @@ -118,6 +119,7 @@ type Server struct {
WebPassword string
ProjectCmdOutputHandler jobs.ProjectCommandOutputHandler
ScheduledExecutorService *scheduled.ExecutorService
EnableServerProfiling bool
}

// Config holds config for server that isn't passed in by the user.
Expand Down Expand Up @@ -145,6 +147,13 @@ type WebhookConfig struct {
Channel string `mapstructure:"channel"`
}

func AttachProfiler(router *mux.Router) {
router.HandleFunc("/debug/pprof/", pprof.Index)
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
}

// NewServer returns a new server. If there are issues starting the server or
// its dependencies an error will be returned. This is like the main() function
// for the server CLI command because it injects all the dependencies.
Expand Down Expand Up @@ -838,6 +847,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
WebUsername: userConfig.WebUsername,
WebPassword: userConfig.WebPassword,
ScheduledExecutorService: scheduledExecutorService,
EnableServerProfiling: userConfig.EnableServerProfiling,
}, nil
}

Expand All @@ -846,6 +856,10 @@ func (s *Server) Start() error {
s.Router.HandleFunc("/", s.Index).Methods("GET").MatcherFunc(func(r *http.Request, rm *mux.RouteMatch) bool {
return r.URL.Path == "/" || r.URL.Path == "/index.html"
})

if s.EnableServerProfiling {
AttachProfiler(s.Router)
}
s.Router.HandleFunc("/healthz", s.Healthz).Methods("GET")
s.Router.HandleFunc("/status", s.StatusController.Get).Methods("GET")
s.Router.PathPrefix("/static/").Handler(http.FileServer(&assetfs.AssetFS{Asset: static.Asset, AssetDir: static.AssetDir, AssetInfo: static.AssetInfo}))
Expand Down
1 change: 1 addition & 0 deletions server/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type UserConfig struct {
EnablePolicyChecksFlag bool `mapstructure:"enable-policy-checks"`
EnableRegExpCmd bool `mapstructure:"enable-regexp-cmd"`
EnableDiffMarkdownFormat bool `mapstructure:"enable-diff-markdown-format"`
EnableServerProfiling bool `mapstructure:"enable-server-profiling"`
GithubAllowMergeableBypassApply bool `mapstructure:"gh-allow-mergeable-bypass-apply"`
GithubHostname string `mapstructure:"gh-hostname"`
GithubToken string `mapstructure:"gh-token"`
Expand Down

0 comments on commit a1b349f

Please sign in to comment.