Skip to content

Commit

Permalink
fix metrics and introspection endpoint enable (#2701)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdn5126 authored Dec 4, 2023
1 parent 9427f7f commit c11acf9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 28 deletions.
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
}

0 comments on commit c11acf9

Please sign in to comment.