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

Fix enabling of Metrics and Introspection Endpoint #2701

Merged
merged 1 commit into from
Dec 4, 2023
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
9 changes: 7 additions & 2 deletions cmd/aws-k8s-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const (

// Environment variable to disable the metrics endpoint on 61678
envDisableMetrics = "DISABLE_METRICS"

// Environment variable to disable the IPAMD introspection endpoint on 61679
envDisableIntrospection = "DISABLE_INTROSPECTION"
)

func main() {
Expand Down Expand Up @@ -74,13 +77,15 @@ func _main() int {
// Pool manager
go ipamContext.StartNodeIPPoolManager()

if utils.GetBoolAsStringEnvVar(envDisableMetrics, false) {
if !utils.GetBoolAsStringEnvVar(envDisableMetrics, false) {
// Prometheus metrics
go metrics.ServeMetrics(metricsPort)
}

// CNI introspection endpoints
go ipamContext.ServeIntrospection()
if !utils.GetBoolAsStringEnvVar(envDisableIntrospection, false) {
go ipamContext.ServeIntrospection()
}

// Start the RPC listener
err = ipamContext.RunRPCHandler(version.Version)
Expand Down
26 changes: 0 additions & 26 deletions pkg/ipamd/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ import (
"net"
"net/http"
"os"
"strconv"
"strings"
"time"

"github.com/aws/amazon-vpc-cni-k8s/pkg/eniconfig"
"github.com/aws/amazon-vpc-cni-k8s/pkg/k8sapi"
"github.com/aws/amazon-vpc-cni-k8s/pkg/networkutils"
"github.com/aws/amazon-vpc-cni-k8s/pkg/utils/retry"
"github.com/aws/amazon-vpc-cni-k8s/utils"
)

const (
Expand All @@ -35,9 +33,6 @@ const (

// Environment variable to define the bind address for the introspection endpoint
introspectionBindAddress = "INTROSPECTION_BIND_ADDRESS"

// Environment variable to disable the introspection endpoints
envDisableIntrospection = "DISABLE_INTROSPECTION"
)

type rootResponse struct {
Expand All @@ -56,11 +51,6 @@ func (lh LoggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

// ServeIntrospection sets up ipamd introspection endpoints
func (c *IPAMContext) ServeIntrospection() {
if disableIntrospection() {
log.Info("Introspection endpoints disabled")
return
}

server := c.setupIntrospectionServer()
for {
_ = retry.WithBackoff(retry.NewSimpleBackoff(time.Second, time.Minute, 0.2, 2), func() error {
Expand Down Expand Up @@ -197,19 +187,3 @@ func logErr(_ int, err error) {
log.Errorf("Write failed: %v", err)
}
}

// disableIntrospection returns true if we should disable the introspection
func disableIntrospection() bool {
return utils.GetBoolAsStringEnvVar(envDisableENIProvisioning, false)
}

func getEnvBoolWithDefault(envName string, def bool) bool {
if strValue := os.Getenv(envName); strValue != "" {
parsedValue, err := strconv.ParseBool(strValue)
if err == nil {
return parsedValue
}
log.Errorf("Failed to parse %s, using default `%t`: %v", envName, def, err.Error())
}
return def
}
Loading