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

[admin] Use OTEL helper instead of tlscfg #6319

Merged
merged 10 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 9 additions & 15 deletions cmd/internal/flags/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"errors"
"flag"
"fmt"
"io"
"net"
"net/http"
"net/http/pprof"
Expand All @@ -35,13 +34,12 @@ var tlsAdminHTTPFlagsConfig = tlscfg.ServerFlagsConfig{

// AdminServer runs an HTTP server with admin endpoints, such as healthcheck at /, /metrics, etc.
type AdminServer struct {
logger *zap.Logger
adminHostPort string
hc *healthcheck.HealthCheck
mux *http.ServeMux
server *http.Server
tlsCfg *tls.Config
tlsCertWatcherCloser io.Closer
logger *zap.Logger
adminHostPort string
hc *healthcheck.HealthCheck
mux *http.ServeMux
server *http.Server
tlsCfg *tls.Config
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
}

// NewAdminServer creates a new admin server.
Expand Down Expand Up @@ -76,20 +74,17 @@ func (s *AdminServer) initFromViper(v *viper.Viper, logger *zap.Logger) error {
s.setLogger(logger)

s.adminHostPort = v.GetString(adminHTTPHostPort)
var tlsAdminHTTP tlscfg.Options
tlsAdminHTTP, err := tlsAdminHTTPFlagsConfig.InitFromViper(v)
tlsAdminHTTPConfig := tlsAdminHTTP.ToOtelServerConfig()
if err != nil {
return fmt.Errorf("failed to parse admin server TLS options: %w", err)
}
chahatsagarmain marked this conversation as resolved.
Show resolved Hide resolved
if tlsAdminHTTP.Enabled {
tlsCfg, err := tlsAdminHTTP.Config(s.logger) // This checks if the certificates are correctly provided
if tlsAdminHTTPConfig != nil {
tlsCfg, err := tlsAdminHTTPConfig.LoadTLSConfig(context.Background()) // This checks if the certificates are correctly provided
if err != nil {
return err
}
s.tlsCfg = tlsCfg
s.tlsCertWatcherCloser = &tlsAdminHTTP
} else {
s.tlsCertWatcherCloser = io.NopCloser(nil)
}
return nil
}
Expand Down Expand Up @@ -160,7 +155,6 @@ func (s *AdminServer) registerPprofHandlers() {
// Close stops the HTTP server
func (s *AdminServer) Close() error {
return errors.Join(
s.tlsCertWatcherCloser.Close(),
s.server.Shutdown(context.Background()),
)
}
4 changes: 2 additions & 2 deletions cmd/internal/flags/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package flags

import (
"context"
"crypto/tls"
"fmt"
"net"
Expand Down Expand Up @@ -133,9 +134,8 @@ func TestAdminServerTLS(t *testing.T) {
adminServer.Serve()
defer adminServer.Close()

clientTLSCfg, err0 := test.clientTLS.Config(zap.NewNop())
clientTLSCfg, err0 := test.clientTLS.ToOtelClientConfig().LoadTLSConfig(context.Background())
require.NoError(t, err0)
defer test.clientTLS.Close()
dialer := &net.Dialer{Timeout: 2 * time.Second}
conn, clientError := tls.DialWithDialer(dialer, "tcp", fmt.Sprintf("localhost:%d", ports.CollectorAdminHTTP), clientTLSCfg)
require.NoError(t, clientError)
Expand Down
Loading