Skip to content

Commit

Permalink
Add missing features to ingress metrics
Browse files Browse the repository at this point in the history
These features have been implemented but are currently not included in the metrics
- SSLPolicy
- Regional Static IP
- Custom Health Checks
  • Loading branch information
spencerhance committed Aug 28, 2020
1 parent d461d45 commit 355178a
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 73 deletions.
9 changes: 8 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,14 @@ func (lbc *LoadBalancerController) sync(key string) error {
lbc.ctx.Recorder(ing.Namespace).Eventf(ing, apiv1.EventTypeWarning, events.SyncIngress, "Error syncing to GCP: %v", syncErr.Error())
} else {
// Insert/update the ingress state for metrics after successful sync.
lbc.metrics.SetIngress(key, metrics.NewIngressState(ing, urlMap.AllServicePorts()))
var fc *frontendconfigv1beta1.FrontendConfig
if flags.F.EnableFrontendConfig {
fc, err = frontendconfig.FrontendConfigForIngress(lbc.ctx.FrontendConfigs().List(), ing)
if err != nil {
return err
}
}
lbc.metrics.SetIngress(key, metrics.NewIngressState(ing, fc, urlMap.AllServicePorts()))
}

// Garbage collection will occur regardless of an error occurring. If an error occurred,
Expand Down
61 changes: 43 additions & 18 deletions pkg/metrics/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"strconv"

"k8s.io/api/networking/v1beta1"
"k8s.io/ingress-gce/pkg/annotations"
frontendconfigv1beta1 "k8s.io/ingress-gce/pkg/apis/frontendconfig/v1beta1"
"k8s.io/ingress-gce/pkg/utils"
"k8s.io/klog"
)
Expand All @@ -44,36 +46,38 @@ const (
// certificate for the Ingress controller to use.
preSharedCertKey = "ingress.gcp.kubernetes.io/pre-shared-cert"
managedCertKey = "networking.gke.io/managed-certificates"
// StaticIPNameKey tells the Ingress controller to use a specific GCE
// StaticGlobalIPNameKey tells the Ingress controller to use a specific GCE
// static ip for its forwarding rules. If specified, the Ingress controller
// assigns the static ip by this name to the forwarding rules of the given
// Ingress. The controller *does not* manage this ip, it is the users
// responsibility to create/delete it.
StaticIPNameKey = "kubernetes.io/ingress.global-static-ip-name"
StaticGlobalIPNameKey = "kubernetes.io/ingress.global-static-ip-name"
// staticIPKey is the annotation key used by controller to record GCP static ip.
staticIPKey = "ingress.kubernetes.io/static-ip"
// SSLCertKey is the annotation key used by controller to record GCP ssl cert.
SSLCertKey = "ingress.kubernetes.io/ssl-cert"

ingress = feature("Ingress")
externalIngress = feature("ExternalIngress")
internalIngress = feature("InternalIngress")
httpEnabled = feature("HTTPEnabled")
hostBasedRouting = feature("HostBasedRouting")
pathBasedRouting = feature("PathBasedRouting")
tlsTermination = feature("TLSTermination")
secretBasedCertsForTLS = feature("SecretBasedCertsForTLS")
preSharedCertsForTLS = feature("PreSharedCertsForTLS")
managedCertsForTLS = feature("ManagedCertsForTLS")
staticGlobalIP = feature("StaticGlobalIP")
managedStaticGlobalIP = feature("ManagedStaticGlobalIP")
specifiedStaticGlobalIP = feature("SpecifiedStaticGlobalIP")
ingress = feature("Ingress")
externalIngress = feature("ExternalIngress")
internalIngress = feature("InternalIngress")
httpEnabled = feature("HTTPEnabled")
hostBasedRouting = feature("HostBasedRouting")
pathBasedRouting = feature("PathBasedRouting")
tlsTermination = feature("TLSTermination")
secretBasedCertsForTLS = feature("SecretBasedCertsForTLS")
preSharedCertsForTLS = feature("PreSharedCertsForTLS")
managedCertsForTLS = feature("ManagedCertsForTLS")
staticGlobalIP = feature("StaticGlobalIP")
managedStaticGlobalIP = feature("ManagedStaticGlobalIP")
specifiedStaticGlobalIP = feature("SpecifiedStaticGlobalIP")
specifiedStaticRegionalIP = feature("SpecifiedStaticRegionalIP")

servicePort = feature("L7LBServicePort")
externalServicePort = feature("L7XLBServicePort")
internalServicePort = feature("L7ILBServicePort")
neg = feature("NEG")

// BackendConfig Features
cloudCDN = feature("CloudCDN")
cloudArmor = feature("CloudArmor")
cloudIAP = feature("CloudIAP")
Expand All @@ -82,6 +86,10 @@ const (
clientIPAffinity = feature("ClientIPAffinity")
cookieAffinity = feature("CookieAffinity")
customRequestHeaders = feature("CustomRequestHeaders")
customHealthChecks = feature("CustomHealthChecks")

// FrontendConfig Features
sslPolicy = feature("SSLPolicy")

standaloneNeg = feature("StandaloneNEG")
ingressNeg = feature("IngressNEG")
Expand All @@ -102,7 +110,7 @@ const (
)

// featuresForIngress returns the list of features for given ingress.
func featuresForIngress(ing *v1beta1.Ingress) []feature {
func featuresForIngress(ing *v1beta1.Ingress, fc *frontendconfigv1beta1.FrontendConfig) []feature {
features := []feature{ingress}

ingKey := fmt.Sprintf("%s/%s", ing.Namespace, ing.Name)
Expand Down Expand Up @@ -191,15 +199,27 @@ func featuresForIngress(ing *v1beta1.Ingress) []feature {
if val, ok := ingAnnotations[staticIPKey]; ok && val != "" {
klog.V(6).Infof("Static IP for ingress %s: %s", ingKey, val)
features = append(features, staticGlobalIP)

// Check if user specified static ip annotation exists.
if val, ok = ingAnnotations[StaticIPNameKey]; ok {
if val, ok = ingAnnotations[StaticGlobalIPNameKey]; ok {
klog.V(6).Infof("User specified static IP for ingress %s: %s", ingKey, val)
features = append(features, specifiedStaticGlobalIP)
} else {
features = append(features, managedStaticGlobalIP)
}
}

// Check for regional static IP
// We do this separately from the global static IP because Controller does not
// populate StaticIPKey annotation when processing Regional static IP.
if val, ok := ingAnnotations[annotations.RegionalStaticIPNameKey]; ok && val != "" {
features = append(features, specifiedStaticRegionalIP)
}

// FrontendConfig Features
if fc != nil && fc.Spec.SslPolicy != nil && *fc.Spec.SslPolicy != "" {
features = append(features, sslPolicy)
}

klog.V(4).Infof("Features for ingress %s: %v", ingKey, features)
return features
}
Expand Down Expand Up @@ -275,6 +295,11 @@ func featuresForServicePort(sp utils.ServicePort) []feature {
klog.V(6).Infof("Custom request headers configured for service port %s: %v", svcPortKey, sp.BackendConfig.Spec.CustomRequestHeaders.Headers)
features = append(features, customRequestHeaders)
}
if sp.BackendConfig.Spec.HealthCheck != nil {
klog.V(6).Infof("Custom health check configured for service port %s: %v", svcPortKey, sp.BackendConfig.Spec.HealthCheck)
features = append(features, customHealthChecks)
}

klog.V(4).Infof("Features for Service port %s: %v", svcPortKey, features)
return features
}
8 changes: 5 additions & 3 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/util/wait"
frontendconfigv1beta1 "k8s.io/ingress-gce/pkg/apis/frontendconfig/v1beta1"
"k8s.io/ingress-gce/pkg/flags"
"k8s.io/ingress-gce/pkg/utils"
"k8s.io/klog"
Expand Down Expand Up @@ -77,8 +78,8 @@ func init() {
}

// NewIngressState returns ingress state for given ingress and service ports.
func NewIngressState(ing *v1beta1.Ingress, svcPorts []utils.ServicePort) IngressState {
return IngressState{ingress: ing, servicePorts: svcPorts}
func NewIngressState(ing *v1beta1.Ingress, fc *frontendconfigv1beta1.FrontendConfig, svcPorts []utils.ServicePort) IngressState {
return IngressState{ingress: ing, frontendconfig: fc, servicePorts: svcPorts}
}

// ControllerMetrics contains the state of the all ingresses.
Expand Down Expand Up @@ -234,7 +235,7 @@ func (im *ControllerMetrics) computeIngressMetrics() (map[feature]int, map[featu
currIngFeatures := make(map[feature]bool)
klog.V(6).Infof("Computing frontend based features for ingress %s", ingKey)
// Add frontend associated ingress features.
for _, feature := range featuresForIngress(ingState.ingress) {
for _, feature := range featuresForIngress(ingState.ingress, ingState.frontendconfig) {
currIngFeatures[feature] = true
}
klog.V(6).Infof("Frontend based features for ingress %s: %v", ingKey, currIngFeatures)
Expand Down Expand Up @@ -371,6 +372,7 @@ func initializeCounts() (map[feature]int, map[feature]int) {
clientIPAffinity: 0,
cookieAffinity: 0,
customRequestHeaders: 0,
sslPolicy: 0,
},
// service port counts
map[feature]int{
Expand Down
Loading

0 comments on commit 355178a

Please sign in to comment.