Repository: kubernetes/kubernetes
File: pkg/kubelet/images/pullmanager/metrics.go (Go)

Code before:
		return err
	}
	m.recordIntentsSize()
	return nil
}

func (m *meteringRecordsAccessor) WriteImagePulledRecord(record *kubeletconfiginternal.ImagePulledRecord) error {
	if err := m.sizeExposedPullRecordsAccessor.WriteImagePulledRecord(record); err != nil {
		return err
	}
	m.recordPulledRecordsSize()
	return nil
}

func (m *meteringRecordsAccessor) DeleteImagePulledRecord(imageRef string) error {
	if err := m.sizeExposedPullRecordsAccessor.DeleteImagePulledRecord(imageRef); err != nil {
		return err
	}
	m.recordPulledRecordsSize()
	return nil
}

func (m *meteringRecordsAccessor) recordIntentsSize() {
	intentsSize, err := m.sizeExposedPullRecordsAccessor.intentsSize()
	if err != nil {
		klog.V(4).InfoS("failed to read number of ImagePullIntents, can't update metric", "metricName", m.intentsSize.Name, "err", err)
		return
	}
	m.intentsSize.Set(float64(intentsSize))
}

func (m *meteringRecordsAccessor) recordPulledRecordsSize() {
	pulledRecordsSize, err := m.sizeExposedPullRecordsAccessor.pulledRecordsSize()
	if err != nil {
		klog.V(4).InfoS("failed to read number of ImagePulledRecords, can't update metric", "metricName", m.pulledRecordsSize.Name, "err", err)
		return
	}
	m.pulledRecordsSize.Set(float64(pulledRecordsSize))
}

func recordMustAttemptImagePullResult(result mustAttemptImagePullResult) {
	mustPullChecksTotal.WithLabelValues(string(result)).Inc()
}


Review comment (suggestion):
These remaining log outputs that still use klog will be replaced with contextual logging in #135992. When making modifications, you should avoid conflicts with #135992.

Additionally, this PR should be merged after #135992 is merged, because follow-up fixes are still required for the part added in #135992 that introduces log levels for Error-level logs.

ref: https://github.com/kubernetes/kubernetes/pull/135992#discussion_r2661386925



Code after:
	m.recordIntentsSize(logger)
	return nil
}

func (m *meteringRecordsAccessor) WriteImagePulledRecord(logger klog.Logger, record *kubeletconfiginternal.ImagePulledRecord) error {
	if err := m.sizeExposedPullRecordsAccessor.WriteImagePulledRecord(logger, record); err != nil {
		return err
	}
	m.recordPulledRecordsSize(logger)
	return nil
}

func (m *meteringRecordsAccessor) DeleteImagePulledRecord(logger klog.Logger, imageRef string) error {
	if err := m.sizeExposedPullRecordsAccessor.DeleteImagePulledRecord(logger, imageRef); err != nil {
		return err
	}
	m.recordPulledRecordsSize(logger)
	return nil
}

func (m *meteringRecordsAccessor) recordIntentsSize(logger klog.Logger) {
	intentsSize, err := m.sizeExposedPullRecordsAccessor.intentsSize()
	if err != nil {
		logger.V(4).Info("failed to read number of ImagePullIntents, can't update metric", "metricName", m.intentsSize.Name, "error", err)
		return
	}
	m.intentsSize.Set(float64(intentsSize))
}

func (m *meteringRecordsAccessor) recordPulledRecordsSize(logger klog.Logger) {
	pulledRecordsSize, err := m.sizeExposedPullRecordsAccessor.pulledRecordsSize()
	if err != nil {
		logger.V(4).Info("failed to read number of ImagePulledRecords, can't update metric", "metricName", m.pulledRecordsSize.Name, "error", err)
		return
	}
	m.pulledRecordsSize.Set(float64(pulledRecordsSize))
}

func recordMustAttemptImagePullResult(result mustAttemptImagePullResult) {
	mustPullChecksTotal.WithLabelValues(string(result)).Inc()
}