Merge pull request #102802 from adisky/metrics-credential-provider-1
Add Metrics for Kubelet credential provider
This commit is contained in:
@@ -86,6 +86,9 @@ func RegisterCredentialProviderPlugins(pluginConfigFile, pluginBinDir string) er
|
||||
return fmt.Errorf("failed to validate credential provider config: %v", errs.ToAggregate())
|
||||
}
|
||||
|
||||
// Register metrics for credential providers
|
||||
registerMetrics()
|
||||
|
||||
for _, provider := range credentialProviderConfig.Providers {
|
||||
pluginBin := filepath.Join(pluginBinDir, provider.Name)
|
||||
if _, err := os.Stat(pluginBin); err != nil {
|
||||
@@ -398,14 +401,8 @@ func (e *execPlugin) ExecPlugin(ctx context.Context, image string) (*credentialp
|
||||
// also, this behaviour is inline with Credential Provider Config spec
|
||||
cmd.Env = mergeEnvVars(e.environ(), configEnvVars)
|
||||
|
||||
err = cmd.Run()
|
||||
if ctx.Err() != nil {
|
||||
return nil, fmt.Errorf("error execing credential provider plugin %s for image %s: %w", e.name, image, ctx.Err())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
klog.V(2).Infof("Error execing credential provider plugin, stderr: %v", stderr.String())
|
||||
return nil, fmt.Errorf("error execing credential provider plugin %s for image %s: %w", e.name, image, err)
|
||||
if err = e.runPlugin(ctx, cmd, image); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data = stdout.Bytes()
|
||||
@@ -428,6 +425,22 @@ func (e *execPlugin) ExecPlugin(ctx context.Context, image string) (*credentialp
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (e *execPlugin) runPlugin(ctx context.Context, cmd *exec.Cmd, image string) error {
|
||||
startTime := time.Now()
|
||||
defer kubeletCredentialProviderPluginDuration.WithLabelValues(e.name).Observe(time.Since(startTime).Seconds())
|
||||
|
||||
err := cmd.Run()
|
||||
if ctx.Err() != nil {
|
||||
kubeletCredentialProviderPluginErrors.WithLabelValues(e.name).Inc()
|
||||
return fmt.Errorf("error execing credential provider plugin %s for image %s: %w", e.name, image, ctx.Err())
|
||||
}
|
||||
if err != nil {
|
||||
kubeletCredentialProviderPluginErrors.WithLabelValues(e.name).Inc()
|
||||
return fmt.Errorf("error execing credential provider plugin %s for image %s: %w", e.name, image, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// encodeRequest encodes the internal CredentialProviderRequest type into the v1alpha1 version in json
|
||||
func (e *execPlugin) encodeRequest(request *credentialproviderapi.CredentialProviderRequest) ([]byte, error) {
|
||||
data, err := runtime.Encode(e.encoder, request)
|
||||
|
Reference in New Issue
Block a user