-
Notifications
You must be signed in to change notification settings - Fork 180
Support scraping metrics from target running with TLS #1190
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
Changes from all commits
bb8696c
5110a95
40e19ae
54dcf0d
d26fb0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,9 +18,11 @@ package runner | |
|
||
import ( | ||
"context" | ||
"crypto/tls" | ||
"errors" | ||
"flag" | ||
"fmt" | ||
"net/http" | ||
"net/http/pprof" | ||
"os" | ||
|
||
|
@@ -138,7 +140,9 @@ var ( | |
|
||
modelServerMetricsPort = flag.Int("model-server-metrics-port", 0, "Port to scrape metrics from pods. "+ | ||
"Default value will be set to InferencePool.Spec.TargetPortNumber if not set.") | ||
modelServerMetricsPath = flag.String("model-server-metrics-path", "/metrics", "Path to scrape metrics from pods") | ||
modelServerMetricsPath = flag.String("model-server-metrics-path", "/metrics", "Path to scrape metrics from pods") | ||
modelServerMetricsScheme = flag.String("model-server-metrics-scheme", "http", "Scheme to scrape metrics from pods") | ||
modelServerMetricsHttpsInsecureSkipVerify = flag.Bool("model-server-metrics-https-insecure-skip-verify", true, "When using 'https' scheme for 'model-server-metrics-scheme', configure 'InsecureSkipVerify' (default to true)") | ||
|
||
setupLog = ctrl.Log.WithName("setup") | ||
) | ||
|
@@ -169,13 +173,15 @@ func (r *Runner) WithSchedulerConfig(schedulerConfig *scheduling.SchedulerConfig | |
func bindEnvToFlags() { | ||
// map[ENV_VAR]flagName – add more as needed | ||
for env, flg := range map[string]string{ | ||
"GRPC_PORT": "grpc-port", | ||
"GRPC_HEALTH_PORT": "grpc-health-port", | ||
"MODEL_SERVER_METRICS_PORT": "model-server-metrics-port", | ||
"MODEL_SERVER_METRICS_PATH": "model-server-metrics-path", | ||
"DESTINATION_ENDPOINT_HINT_KEY": "destination-endpoint-hint-key", | ||
"POOL_NAME": "pool-name", | ||
"POOL_NAMESPACE": "pool-namespace", | ||
"GRPC_PORT": "grpc-port", | ||
"GRPC_HEALTH_PORT": "grpc-health-port", | ||
"MODEL_SERVER_METRICS_PORT": "model-server-metrics-port", | ||
"MODEL_SERVER_METRICS_PATH": "model-server-metrics-path", | ||
"MODEL_SERVER_METRICS_SCHEME": "model-server-metrics-scheme", | ||
"MODEL_SERVER_METRICS_HTTPS_INSECURE_SKIP_VERIFY": "model-server-metrics-https-insecure-skip-verify", | ||
"DESTINATION_ENDPOINT_HINT_KEY": "destination-endpoint-hint-key", | ||
"POOL_NAME": "pool-name", | ||
"POOL_NAMESPACE": "pool-namespace", | ||
// durations & bools work too; flag.Set expects the *string* form | ||
"REFRESH_METRICS_INTERVAL": "refresh-metrics-interval", | ||
"SECURE_SERVING": "secure-serving", | ||
|
@@ -235,10 +241,26 @@ func (r *Runner) Run(ctx context.Context) error { | |
return err | ||
} | ||
verifyMetricMapping(*mapping, setupLog) | ||
|
||
var metricsHttpClient *http.Client | ||
if *modelServerMetricsScheme == "https" { | ||
metricsHttpClient = &http.Client{ | ||
Transport: &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
InsecureSkipVerify: *modelServerMetricsHttpsInsecureSkipVerify, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is the CA added to the TLS context? Is it intended to be added to the default certificate roots in the image? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, we should actually remove the flag for now and set this to true There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Go, we can inject the default loaded CA certs file and dirs paths via env variables https://go.dev/src/crypto/x509/root_unix.go or use well-known files/directories https://go.dev/src/crypto/x509/root_linux.go: // certFileEnv is the environment variable which identifies where to locate
// the SSL certificate file. If set this overrides the system default.
certFileEnv = "SSL_CERT_FILE"
// certDirEnv is the environment variable which identifies which directory
// to check for SSL certificate files. If set this overrides the system default.
// It is a colon separated list of directories.
// See https://www.openssl.org/docs/man1.0.2/man1/c_rehash.html.
certDirEnv = "SSL_CERT_DIR" // Possible certificate files; stop after finding one.
var certFiles = []string{
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
"/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL 6
"/etc/ssl/ca-bundle.pem", // OpenSUSE
"/etc/pki/tls/cacert.pem", // OpenELEC
"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem", // CentOS/RHEL 7
"/etc/ssl/cert.pem", // Alpine Linux
}
// Possible directories with certificate files; all will be read.
var certDirectories = []string{
"/etc/ssl/certs", // SLES10/SLES11, https://golang.org/issue/12139
"/etc/pki/tls/certs", // Fedora/RHEL
}
func init() {
if goos.IsAndroid == 1 {
certDirectories = append(certDirectories,
"/system/etc/security/cacerts", // Android system roots
"/data/misc/keychain/certs-added", // User trusted CA folder
)
}
} do we still want to add the explicit CA path flags or we can leverage built-in/standard methods to inject custom CA bundles? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pierDipi as far as I can tell, this configures Go for directory locations where CA files are located. |
||
}, | ||
}, | ||
} | ||
} else { | ||
metricsHttpClient = http.DefaultClient | ||
} | ||
|
||
pmf := backendmetrics.NewPodMetricsFactory(&backendmetrics.PodMetricsClientImpl{ | ||
MetricMapping: mapping, | ||
ModelServerMetricsPort: int32(*modelServerMetricsPort), | ||
ModelServerMetricsPath: *modelServerMetricsPath, | ||
MetricMapping: mapping, | ||
ModelServerMetricsPort: int32(*modelServerMetricsPort), | ||
ModelServerMetricsPath: *modelServerMetricsPath, | ||
ModelServerMetricsScheme: *modelServerMetricsScheme, | ||
Client: metricsHttpClient, | ||
}, *refreshMetricsInterval) | ||
|
||
datastore := datastore.NewDatastore(ctx, pmf) | ||
|
@@ -421,6 +443,9 @@ func validateFlags() error { | |
if *configText != "" && *configFile != "" { | ||
return fmt.Errorf("both the %q and %q flags can not be set at the same time", "configText", "configFile") | ||
} | ||
if *modelServerMetricsScheme != "http" && *modelServerMetricsScheme != "https" { | ||
return fmt.Errorf("unexpected %q value for %q flag, it can only be set to 'http' or 'https'", *modelServerMetricsScheme, "model-server-metrics-scheme") | ||
} | ||
|
||
return nil | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Do you mind adding these flags (with the same defaults) to the helm chart? Example:
gateway-api-inference-extension/config/charts/inferencepool/templates/epp-deployment.yaml
Line 41 in 6cf8f31
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback Kellen, done!