Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support https configuration #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions docs/reference-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ minion:
exporter:
# Namespace is the prefix for all exported Prometheus metrics
namespace: "kminion"
# Host that shall be used to bind the HTTP server on
# Host that shall be used to bind the HTTP(S) server on
host: ""
# Port that shall be used to bind the HTTP server on
# Port that shall be used to bind the HTTP(S) server on
port: 8080
# Certificate file to be used if configuring as a HTTPS server, leave empty to configure as a HTTP server
tlsCertificate: ""
# Key file to be used if configuring as a HTTPS server, ignored if tlsCertificate isnt set
tlsKey: ""
Comment on lines +175 to +178
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Certificate file to be used if configuring as a HTTPS server, leave empty to configure as a HTTP server
tlsCertificate: ""
# Key file to be used if configuring as a HTTPS server, ignored if tlsCertificate isnt set
tlsKey: ""
# Certificate file to be used if configuring as an HTTPS server, leave empty to configure as an HTTP server
tlsCertFilepath: ""
# Key file to be used if configuring as a HTTPS server, ignored if tlsCertFilepath isn't set
tlsKeyFilepath: ""

15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,21 @@ func main() {
go func() {
<-ctx.Done()
if err := srv.Shutdown(context.Background()); err != nil {
logger.Error("error stopping HTTP server", zap.Error(err))
logger.Error("error stopping server", zap.Error(err))
os.Exit(1)
}
}()
logger.Info("listening on address", zap.String("listen_address", address))
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Error("error starting HTTP server", zap.Error(err))
os.Exit(1)
if cfg.Exporter.TLSCertFile != "" {
if err := srv.ListenAndServeTLS(cfg.Exporter.TLSCertFile, cfg.Exporter.TLSKeyFile); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Error("error starting HTTPS server", zap.Error(err))
os.Exit(1)
}
} else {
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
logger.Error("error starting HTTP server", zap.Error(err))
os.Exit(1)
}
}

logger.Info("kminion stopped")
Expand Down
8 changes: 5 additions & 3 deletions prometheus/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package prometheus

type Config struct {
Host string `koanf:"host"`
Port int `koanf:"port"`
Namespace string `koanf:"namespace"`
Host string `koanf:"host"`
Port int `koanf:"port"`
Namespace string `koanf:"namespace"`
TLSCertFile string `koanf:"tlsCertificate"`
TLSKeyFile string `koanf:"tlsKey"`
Comment on lines +7 to +8
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried to update this into your branch, but I didn't have permissions to do changes. A minor change for consistency with other TLS configs (kafka.tls)

Suggested change
TLSCertFile string `koanf:"tlsCertificate"`
TLSKeyFile string `koanf:"tlsKey"`
TLSCertFile string `koanf:"tlsCertFilepath"`
TLSKeyFile string `koanf:"tlsKeyFilepath"`

}

func (c *Config) SetDefaults() {
Expand Down