rename buildStore to buildStores

This commit is contained in:
fpetkovski 2021-06-25 14:23:09 +02:00
parent acb7d1dd3c
commit a6eb25e3c6
5 changed files with 111 additions and 111 deletions

View File

@ -67,7 +67,7 @@ type Builder struct {
shardingMetrics *sharding.Metrics shardingMetrics *sharding.Metrics
shard int32 shard int32
totalShards int totalShards int
buildStoreFunc ksmtypes.BuildStoreFunc buildStoresFunc ksmtypes.BuildStoresFunc
allowLabelsList map[string][]string allowLabelsList map[string][]string
} }
@ -136,14 +136,14 @@ func (b *Builder) WithAllowDenyList(l ksmtypes.AllowDenyLister) {
b.allowDenyList = l b.allowDenyList = l
} }
// WithGenerateStoreFunc configures a custom generate store function // WithGenerateStoresFunc configures a custom generate store function
func (b *Builder) WithGenerateStoreFunc(f ksmtypes.BuildStoreFunc) { func (b *Builder) WithGenerateStoresFunc(f ksmtypes.BuildStoresFunc) {
b.buildStoreFunc = f b.buildStoresFunc = f
} }
// DefaultGenerateStoreFunc returns default buildStore function // DefaultGenerateStoresFunc returns default buildStores function
func (b *Builder) DefaultGenerateStoreFunc() ksmtypes.BuildStoreFunc { func (b *Builder) DefaultGenerateStoresFunc() ksmtypes.BuildStoresFunc {
return b.buildStore return b.buildStores
} }
// WithAllowLabels configures which labels can be returned for metrics // WithAllowLabels configures which labels can be returned for metrics
@ -183,35 +183,35 @@ func (b *Builder) Build() []metricsstore.MetricsWriter {
} }
var availableStores = map[string]func(f *Builder) []*metricsstore.MetricsStore{ var availableStores = map[string]func(f *Builder) []*metricsstore.MetricsStore{
"certificatesigningrequests": func(b *Builder) []*metricsstore.MetricsStore { return b.buildCsrStore() }, "certificatesigningrequests": func(b *Builder) []*metricsstore.MetricsStore { return b.buildCsrStores() },
"configmaps": func(b *Builder) []*metricsstore.MetricsStore { return b.buildConfigMapStore() }, "configmaps": func(b *Builder) []*metricsstore.MetricsStore { return b.buildConfigMapStores() },
"cronjobs": func(b *Builder) []*metricsstore.MetricsStore { return b.buildCronJobStore() }, "cronjobs": func(b *Builder) []*metricsstore.MetricsStore { return b.buildCronJobStores() },
"daemonsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildDaemonSetStore() }, "daemonsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildDaemonSetStores() },
"deployments": func(b *Builder) []*metricsstore.MetricsStore { return b.buildDeploymentStore() }, "deployments": func(b *Builder) []*metricsstore.MetricsStore { return b.buildDeploymentStores() },
"endpoints": func(b *Builder) []*metricsstore.MetricsStore { return b.buildEndpointsStore() }, "endpoints": func(b *Builder) []*metricsstore.MetricsStore { return b.buildEndpointsStores() },
"horizontalpodautoscalers": func(b *Builder) []*metricsstore.MetricsStore { return b.buildHPAStore() }, "horizontalpodautoscalers": func(b *Builder) []*metricsstore.MetricsStore { return b.buildHPAStores() },
"ingresses": func(b *Builder) []*metricsstore.MetricsStore { return b.buildIngressStore() }, "ingresses": func(b *Builder) []*metricsstore.MetricsStore { return b.buildIngressStores() },
"jobs": func(b *Builder) []*metricsstore.MetricsStore { return b.buildJobStore() }, "jobs": func(b *Builder) []*metricsstore.MetricsStore { return b.buildJobStores() },
"leases": func(b *Builder) []*metricsstore.MetricsStore { return b.buildLeases() }, "leases": func(b *Builder) []*metricsstore.MetricsStore { return b.buildLeasesStores() },
"limitranges": func(b *Builder) []*metricsstore.MetricsStore { return b.buildLimitRangeStore() }, "limitranges": func(b *Builder) []*metricsstore.MetricsStore { return b.buildLimitRangeStores() },
"mutatingwebhookconfigurations": func(b *Builder) []*metricsstore.MetricsStore { return b.buildMutatingWebhookConfigurationStore() }, "mutatingwebhookconfigurations": func(b *Builder) []*metricsstore.MetricsStore { return b.buildMutatingWebhookConfigurationStores() },
"namespaces": func(b *Builder) []*metricsstore.MetricsStore { return b.buildNamespaceStore() }, "namespaces": func(b *Builder) []*metricsstore.MetricsStore { return b.buildNamespaceStores() },
"networkpolicies": func(b *Builder) []*metricsstore.MetricsStore { return b.buildNetworkPolicyStore() }, "networkpolicies": func(b *Builder) []*metricsstore.MetricsStore { return b.buildNetworkPolicyStores() },
"nodes": func(b *Builder) []*metricsstore.MetricsStore { return b.buildNodeStore() }, "nodes": func(b *Builder) []*metricsstore.MetricsStore { return b.buildNodeStores() },
"persistentvolumeclaims": func(b *Builder) []*metricsstore.MetricsStore { return b.buildPersistentVolumeClaimStore() }, "persistentvolumeclaims": func(b *Builder) []*metricsstore.MetricsStore { return b.buildPersistentVolumeClaimStores() },
"persistentvolumes": func(b *Builder) []*metricsstore.MetricsStore { return b.buildPersistentVolumeStore() }, "persistentvolumes": func(b *Builder) []*metricsstore.MetricsStore { return b.buildPersistentVolumeStores() },
"poddisruptionbudgets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildPodDisruptionBudgetStore() }, "poddisruptionbudgets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildPodDisruptionBudgetStores() },
"pods": func(b *Builder) []*metricsstore.MetricsStore { return b.buildPodStore() }, "pods": func(b *Builder) []*metricsstore.MetricsStore { return b.buildPodStores() },
"replicasets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildReplicaSetStore() }, "replicasets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildReplicaSetStores() },
"replicationcontrollers": func(b *Builder) []*metricsstore.MetricsStore { return b.buildReplicationControllerStore() }, "replicationcontrollers": func(b *Builder) []*metricsstore.MetricsStore { return b.buildReplicationControllerStores() },
"resourcequotas": func(b *Builder) []*metricsstore.MetricsStore { return b.buildResourceQuotaStore() }, "resourcequotas": func(b *Builder) []*metricsstore.MetricsStore { return b.buildResourceQuotaStores() },
"secrets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildSecretStore() }, "secrets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildSecretStores() },
"services": func(b *Builder) []*metricsstore.MetricsStore { return b.buildServiceStore() }, "services": func(b *Builder) []*metricsstore.MetricsStore { return b.buildServiceStores() },
"statefulsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildStatefulSetStore() }, "statefulsets": func(b *Builder) []*metricsstore.MetricsStore { return b.buildStatefulSetStores() },
"storageclasses": func(b *Builder) []*metricsstore.MetricsStore { return b.buildStorageClassStore() }, "storageclasses": func(b *Builder) []*metricsstore.MetricsStore { return b.buildStorageClassStores() },
"validatingwebhookconfigurations": func(b *Builder) []*metricsstore.MetricsStore { return b.buildValidatingWebhookConfigurationStore() }, "validatingwebhookconfigurations": func(b *Builder) []*metricsstore.MetricsStore { return b.buildValidatingWebhookConfigurationStores() },
"volumeattachments": func(b *Builder) []*metricsstore.MetricsStore { return b.buildVolumeAttachmentStore() }, "volumeattachments": func(b *Builder) []*metricsstore.MetricsStore { return b.buildVolumeAttachmentStores() },
"verticalpodautoscalers": func(b *Builder) []*metricsstore.MetricsStore { return b.buildVPAStore() }, "verticalpodautoscalers": func(b *Builder) []*metricsstore.MetricsStore { return b.buildVPAStores() },
} }
func resourceExists(name string) bool { func resourceExists(name string) bool {
@ -227,123 +227,123 @@ func availableResources() []string {
return c return c
} }
func (b *Builder) buildConfigMapStore() []*metricsstore.MetricsStore { func (b *Builder) buildConfigMapStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(configMapMetricFamilies, &v1.ConfigMap{}, createConfigMapListWatch) return b.buildStoresFunc(configMapMetricFamilies, &v1.ConfigMap{}, createConfigMapListWatch)
} }
func (b *Builder) buildCronJobStore() []*metricsstore.MetricsStore { func (b *Builder) buildCronJobStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(cronJobMetricFamilies(b.allowLabelsList["cronjobs"]), &batchv1beta1.CronJob{}, createCronJobListWatch) return b.buildStoresFunc(cronJobMetricFamilies(b.allowLabelsList["cronjobs"]), &batchv1beta1.CronJob{}, createCronJobListWatch)
} }
func (b *Builder) buildDaemonSetStore() []*metricsstore.MetricsStore { func (b *Builder) buildDaemonSetStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(daemonSetMetricFamilies(b.allowLabelsList["daemonsets"]), &appsv1.DaemonSet{}, createDaemonSetListWatch) return b.buildStoresFunc(daemonSetMetricFamilies(b.allowLabelsList["daemonsets"]), &appsv1.DaemonSet{}, createDaemonSetListWatch)
} }
func (b *Builder) buildDeploymentStore() []*metricsstore.MetricsStore { func (b *Builder) buildDeploymentStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(deploymentMetricFamilies(b.allowLabelsList["deployments"]), &appsv1.Deployment{}, createDeploymentListWatch) return b.buildStoresFunc(deploymentMetricFamilies(b.allowLabelsList["deployments"]), &appsv1.Deployment{}, createDeploymentListWatch)
} }
func (b *Builder) buildEndpointsStore() []*metricsstore.MetricsStore { func (b *Builder) buildEndpointsStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(endpointMetricFamilies(b.allowLabelsList["endpoints"]), &v1.Endpoints{}, createEndpointsListWatch) return b.buildStoresFunc(endpointMetricFamilies(b.allowLabelsList["endpoints"]), &v1.Endpoints{}, createEndpointsListWatch)
} }
func (b *Builder) buildHPAStore() []*metricsstore.MetricsStore { func (b *Builder) buildHPAStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(hpaMetricFamilies(b.allowLabelsList["horizontalpodautoscalers"]), &autoscaling.HorizontalPodAutoscaler{}, createHPAListWatch) return b.buildStoresFunc(hpaMetricFamilies(b.allowLabelsList["horizontalpodautoscalers"]), &autoscaling.HorizontalPodAutoscaler{}, createHPAListWatch)
} }
func (b *Builder) buildIngressStore() []*metricsstore.MetricsStore { func (b *Builder) buildIngressStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(ingressMetricFamilies(b.allowLabelsList["ingresses"]), &networkingv1.Ingress{}, createIngressListWatch) return b.buildStoresFunc(ingressMetricFamilies(b.allowLabelsList["ingresses"]), &networkingv1.Ingress{}, createIngressListWatch)
} }
func (b *Builder) buildJobStore() []*metricsstore.MetricsStore { func (b *Builder) buildJobStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(jobMetricFamilies(b.allowLabelsList["jobs"]), &batchv1.Job{}, createJobListWatch) return b.buildStoresFunc(jobMetricFamilies(b.allowLabelsList["jobs"]), &batchv1.Job{}, createJobListWatch)
} }
func (b *Builder) buildLimitRangeStore() []*metricsstore.MetricsStore { func (b *Builder) buildLimitRangeStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(limitRangeMetricFamilies, &v1.LimitRange{}, createLimitRangeListWatch) return b.buildStoresFunc(limitRangeMetricFamilies, &v1.LimitRange{}, createLimitRangeListWatch)
} }
func (b *Builder) buildMutatingWebhookConfigurationStore() []*metricsstore.MetricsStore { func (b *Builder) buildMutatingWebhookConfigurationStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(mutatingWebhookConfigurationMetricFamilies, &admissionregistrationv1.MutatingWebhookConfiguration{}, createMutatingWebhookConfigurationListWatch) return b.buildStoresFunc(mutatingWebhookConfigurationMetricFamilies, &admissionregistrationv1.MutatingWebhookConfiguration{}, createMutatingWebhookConfigurationListWatch)
} }
func (b *Builder) buildNamespaceStore() []*metricsstore.MetricsStore { func (b *Builder) buildNamespaceStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(namespaceMetricFamilies(b.allowLabelsList["namespaces"]), &v1.Namespace{}, createNamespaceListWatch) return b.buildStoresFunc(namespaceMetricFamilies(b.allowLabelsList["namespaces"]), &v1.Namespace{}, createNamespaceListWatch)
} }
func (b *Builder) buildNetworkPolicyStore() []*metricsstore.MetricsStore { func (b *Builder) buildNetworkPolicyStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(networkPolicyMetricFamilies(b.allowLabelsList["networkpolicies"]), &networkingv1.NetworkPolicy{}, createNetworkPolicyListWatch) return b.buildStoresFunc(networkPolicyMetricFamilies(b.allowLabelsList["networkpolicies"]), &networkingv1.NetworkPolicy{}, createNetworkPolicyListWatch)
} }
func (b *Builder) buildNodeStore() []*metricsstore.MetricsStore { func (b *Builder) buildNodeStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(nodeMetricFamilies(b.allowLabelsList["nodes"]), &v1.Node{}, createNodeListWatch) return b.buildStoresFunc(nodeMetricFamilies(b.allowLabelsList["nodes"]), &v1.Node{}, createNodeListWatch)
} }
func (b *Builder) buildPersistentVolumeClaimStore() []*metricsstore.MetricsStore { func (b *Builder) buildPersistentVolumeClaimStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(persistentVolumeClaimMetricFamilies(b.allowLabelsList["persistentvolumeclaims"]), &v1.PersistentVolumeClaim{}, createPersistentVolumeClaimListWatch) return b.buildStoresFunc(persistentVolumeClaimMetricFamilies(b.allowLabelsList["persistentvolumeclaims"]), &v1.PersistentVolumeClaim{}, createPersistentVolumeClaimListWatch)
} }
func (b *Builder) buildPersistentVolumeStore() []*metricsstore.MetricsStore { func (b *Builder) buildPersistentVolumeStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(persistentVolumeMetricFamilies(b.allowLabelsList["persistentvolumes"]), &v1.PersistentVolume{}, createPersistentVolumeListWatch) return b.buildStoresFunc(persistentVolumeMetricFamilies(b.allowLabelsList["persistentvolumes"]), &v1.PersistentVolume{}, createPersistentVolumeListWatch)
} }
func (b *Builder) buildPodDisruptionBudgetStore() []*metricsstore.MetricsStore { func (b *Builder) buildPodDisruptionBudgetStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(podDisruptionBudgetMetricFamilies, &policy.PodDisruptionBudget{}, createPodDisruptionBudgetListWatch) return b.buildStoresFunc(podDisruptionBudgetMetricFamilies, &policy.PodDisruptionBudget{}, createPodDisruptionBudgetListWatch)
} }
func (b *Builder) buildReplicaSetStore() []*metricsstore.MetricsStore { func (b *Builder) buildReplicaSetStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(replicaSetMetricFamilies(b.allowLabelsList["replicasets"]), &appsv1.ReplicaSet{}, createReplicaSetListWatch) return b.buildStoresFunc(replicaSetMetricFamilies(b.allowLabelsList["replicasets"]), &appsv1.ReplicaSet{}, createReplicaSetListWatch)
} }
func (b *Builder) buildReplicationControllerStore() []*metricsstore.MetricsStore { func (b *Builder) buildReplicationControllerStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(replicationControllerMetricFamilies, &v1.ReplicationController{}, createReplicationControllerListWatch) return b.buildStoresFunc(replicationControllerMetricFamilies, &v1.ReplicationController{}, createReplicationControllerListWatch)
} }
func (b *Builder) buildResourceQuotaStore() []*metricsstore.MetricsStore { func (b *Builder) buildResourceQuotaStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(resourceQuotaMetricFamilies, &v1.ResourceQuota{}, createResourceQuotaListWatch) return b.buildStoresFunc(resourceQuotaMetricFamilies, &v1.ResourceQuota{}, createResourceQuotaListWatch)
} }
func (b *Builder) buildSecretStore() []*metricsstore.MetricsStore { func (b *Builder) buildSecretStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(secretMetricFamilies(b.allowLabelsList["secrets"]), &v1.Secret{}, createSecretListWatch) return b.buildStoresFunc(secretMetricFamilies(b.allowLabelsList["secrets"]), &v1.Secret{}, createSecretListWatch)
} }
func (b *Builder) buildServiceStore() []*metricsstore.MetricsStore { func (b *Builder) buildServiceStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(serviceMetricFamilies(b.allowLabelsList["services"]), &v1.Service{}, createServiceListWatch) return b.buildStoresFunc(serviceMetricFamilies(b.allowLabelsList["services"]), &v1.Service{}, createServiceListWatch)
} }
func (b *Builder) buildStatefulSetStore() []*metricsstore.MetricsStore { func (b *Builder) buildStatefulSetStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(statefulSetMetricFamilies(b.allowLabelsList["statefulsets"]), &appsv1.StatefulSet{}, createStatefulSetListWatch) return b.buildStoresFunc(statefulSetMetricFamilies(b.allowLabelsList["statefulsets"]), &appsv1.StatefulSet{}, createStatefulSetListWatch)
} }
func (b *Builder) buildStorageClassStore() []*metricsstore.MetricsStore { func (b *Builder) buildStorageClassStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(storageClassMetricFamilies(b.allowLabelsList["storageclasses"]), &storagev1.StorageClass{}, createStorageClassListWatch) return b.buildStoresFunc(storageClassMetricFamilies(b.allowLabelsList["storageclasses"]), &storagev1.StorageClass{}, createStorageClassListWatch)
} }
func (b *Builder) buildPodStore() []*metricsstore.MetricsStore { func (b *Builder) buildPodStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(podMetricFamilies(b.allowLabelsList["pods"]), &v1.Pod{}, createPodListWatch) return b.buildStoresFunc(podMetricFamilies(b.allowLabelsList["pods"]), &v1.Pod{}, createPodListWatch)
} }
func (b *Builder) buildCsrStore() []*metricsstore.MetricsStore { func (b *Builder) buildCsrStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(csrMetricFamilies(b.allowLabelsList["certificatesigningrequests"]), &certv1.CertificateSigningRequest{}, createCSRListWatch) return b.buildStoresFunc(csrMetricFamilies(b.allowLabelsList["certificatesigningrequests"]), &certv1.CertificateSigningRequest{}, createCSRListWatch)
} }
func (b *Builder) buildValidatingWebhookConfigurationStore() []*metricsstore.MetricsStore { func (b *Builder) buildValidatingWebhookConfigurationStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(validatingWebhookConfigurationMetricFamilies, &admissionregistrationv1.ValidatingWebhookConfiguration{}, createValidatingWebhookConfigurationListWatch) return b.buildStoresFunc(validatingWebhookConfigurationMetricFamilies, &admissionregistrationv1.ValidatingWebhookConfiguration{}, createValidatingWebhookConfigurationListWatch)
} }
func (b *Builder) buildVolumeAttachmentStore() []*metricsstore.MetricsStore { func (b *Builder) buildVolumeAttachmentStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(volumeAttachmentMetricFamilies, &storagev1.VolumeAttachment{}, createVolumeAttachmentListWatch) return b.buildStoresFunc(volumeAttachmentMetricFamilies, &storagev1.VolumeAttachment{}, createVolumeAttachmentListWatch)
} }
func (b *Builder) buildVPAStore() []*metricsstore.MetricsStore { func (b *Builder) buildVPAStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(vpaMetricFamilies(b.allowLabelsList["verticalpodautoscalers"]), &vpaautoscaling.VerticalPodAutoscaler{}, createVPAListWatchFunc(b.vpaClient)) return b.buildStoresFunc(vpaMetricFamilies(b.allowLabelsList["verticalpodautoscalers"]), &vpaautoscaling.VerticalPodAutoscaler{}, createVPAListWatchFunc(b.vpaClient))
} }
func (b *Builder) buildLeases() []*metricsstore.MetricsStore { func (b *Builder) buildLeasesStores() []*metricsstore.MetricsStore {
return b.buildStoreFunc(leaseMetricFamilies, &coordinationv1.Lease{}, createLeaseListWatch) return b.buildStoresFunc(leaseMetricFamilies, &coordinationv1.Lease{}, createLeaseListWatch)
} }
func (b *Builder) buildStore( func (b *Builder) buildStores(
metricFamilies []generator.FamilyGenerator, metricFamilies []generator.FamilyGenerator,
expectedType interface{}, expectedType interface{},
listWatchFunc func(kubeClient clientset.Interface, ns string) cache.ListerWatcher, listWatchFunc func(kubeClient clientset.Interface, ns string) cache.ListerWatcher,

View File

@ -139,7 +139,7 @@ func main() {
storeBuilder.WithAllowDenyList(allowDenyList) storeBuilder.WithAllowDenyList(allowDenyList)
storeBuilder.WithGenerateStoreFunc(storeBuilder.DefaultGenerateStoreFunc()) storeBuilder.WithGenerateStoresFunc(storeBuilder.DefaultGenerateStoresFunc())
proc.StartReaper() proc.StartReaper()

View File

@ -67,7 +67,7 @@ func BenchmarkKubeStateMetrics(b *testing.B) {
builder.WithSharding(0, 1) builder.WithSharding(0, 1)
builder.WithContext(ctx) builder.WithContext(ctx)
builder.WithNamespaces(options.DefaultNamespaces) builder.WithNamespaces(options.DefaultNamespaces)
builder.WithGenerateStoreFunc(builder.DefaultGenerateStoreFunc()) builder.WithGenerateStoresFunc(builder.DefaultGenerateStoresFunc())
l, err := allowdenylist.New(map[string]struct{}{}, map[string]struct{}{}) l, err := allowdenylist.New(map[string]struct{}{}, map[string]struct{}{})
if err != nil { if err != nil {
@ -132,7 +132,7 @@ func TestFullScrapeCycle(t *testing.T) {
builder.WithEnabledResources(options.DefaultResources.AsSlice()) builder.WithEnabledResources(options.DefaultResources.AsSlice())
builder.WithKubeClient(kubeClient) builder.WithKubeClient(kubeClient)
builder.WithNamespaces(options.DefaultNamespaces) builder.WithNamespaces(options.DefaultNamespaces)
builder.WithGenerateStoreFunc(builder.DefaultGenerateStoreFunc()) builder.WithGenerateStoresFunc(builder.DefaultGenerateStoresFunc())
l, err := allowdenylist.New(map[string]struct{}{}, map[string]struct{}{}) l, err := allowdenylist.New(map[string]struct{}{}, map[string]struct{}{})
if err != nil { if err != nil {
@ -412,7 +412,7 @@ func TestShardingEquivalenceScrapeCycle(t *testing.T) {
unshardedBuilder.WithNamespaces(options.DefaultNamespaces) unshardedBuilder.WithNamespaces(options.DefaultNamespaces)
unshardedBuilder.WithAllowDenyList(l) unshardedBuilder.WithAllowDenyList(l)
unshardedBuilder.WithAllowLabels(map[string][]string{}) unshardedBuilder.WithAllowLabels(map[string][]string{})
unshardedBuilder.WithGenerateStoreFunc(unshardedBuilder.DefaultGenerateStoreFunc()) unshardedBuilder.WithGenerateStoresFunc(unshardedBuilder.DefaultGenerateStoresFunc())
unshardedHandler := metricshandler.New(&options.Options{}, kubeClient, unshardedBuilder, false) unshardedHandler := metricshandler.New(&options.Options{}, kubeClient, unshardedBuilder, false)
unshardedHandler.ConfigureSharding(ctx, 0, 1) unshardedHandler.ConfigureSharding(ctx, 0, 1)
@ -425,7 +425,7 @@ func TestShardingEquivalenceScrapeCycle(t *testing.T) {
shardedBuilder1.WithNamespaces(options.DefaultNamespaces) shardedBuilder1.WithNamespaces(options.DefaultNamespaces)
shardedBuilder1.WithAllowDenyList(l) shardedBuilder1.WithAllowDenyList(l)
shardedBuilder1.WithAllowLabels(map[string][]string{}) shardedBuilder1.WithAllowLabels(map[string][]string{})
shardedBuilder1.WithGenerateStoreFunc(shardedBuilder1.DefaultGenerateStoreFunc()) shardedBuilder1.WithGenerateStoresFunc(shardedBuilder1.DefaultGenerateStoresFunc())
shardedHandler1 := metricshandler.New(&options.Options{}, kubeClient, shardedBuilder1, false) shardedHandler1 := metricshandler.New(&options.Options{}, kubeClient, shardedBuilder1, false)
shardedHandler1.ConfigureSharding(ctx, 0, 2) shardedHandler1.ConfigureSharding(ctx, 0, 2)
@ -438,7 +438,7 @@ func TestShardingEquivalenceScrapeCycle(t *testing.T) {
shardedBuilder2.WithNamespaces(options.DefaultNamespaces) shardedBuilder2.WithNamespaces(options.DefaultNamespaces)
shardedBuilder2.WithAllowDenyList(l) shardedBuilder2.WithAllowDenyList(l)
shardedBuilder2.WithAllowLabels(map[string][]string{}) shardedBuilder2.WithAllowLabels(map[string][]string{})
shardedBuilder2.WithGenerateStoreFunc(shardedBuilder2.DefaultGenerateStoreFunc()) shardedBuilder2.WithGenerateStoresFunc(shardedBuilder2.DefaultGenerateStoresFunc())
shardedHandler2 := metricshandler.New(&options.Options{}, kubeClient, shardedBuilder2, false) shardedHandler2 := metricshandler.New(&options.Options{}, kubeClient, shardedBuilder2, false)
shardedHandler2.ConfigureSharding(ctx, 1, 2) shardedHandler2.ConfigureSharding(ctx, 1, 2)

View File

@ -90,14 +90,14 @@ func (b *Builder) WithAllowLabels(l map[string][]string) {
b.internal.WithAllowLabels(l) b.internal.WithAllowLabels(l)
} }
// WithGenerateStoreFunc configures a custom generate store function // WithGenerateStoresFunc configures a custom generate store function
func (b *Builder) WithGenerateStoreFunc(f ksmtypes.BuildStoreFunc) { func (b *Builder) WithGenerateStoresFunc(f ksmtypes.BuildStoresFunc) {
b.internal.WithGenerateStoreFunc(f) b.internal.WithGenerateStoresFunc(f)
} }
// DefaultGenerateStoreFunc returns default buildStore function // DefaultGenerateStoresFunc returns default buildStore function
func (b *Builder) DefaultGenerateStoreFunc() ksmtypes.BuildStoreFunc { func (b *Builder) DefaultGenerateStoresFunc() ksmtypes.BuildStoresFunc {
return b.internal.DefaultGenerateStoreFunc() return b.internal.DefaultGenerateStoresFunc()
} }
// Build initializes and registers all enabled stores. // Build initializes and registers all enabled stores.

View File

@ -40,14 +40,14 @@ type BuilderInterface interface {
WithKubeClient(c clientset.Interface) WithKubeClient(c clientset.Interface)
WithVPAClient(c vpaclientset.Interface) WithVPAClient(c vpaclientset.Interface)
WithAllowDenyList(l AllowDenyLister) WithAllowDenyList(l AllowDenyLister)
WithGenerateStoreFunc(f BuildStoreFunc)
WithAllowLabels(l map[string][]string) WithAllowLabels(l map[string][]string)
DefaultGenerateStoreFunc() BuildStoreFunc WithGenerateStoresFunc(f BuildStoresFunc)
DefaultGenerateStoresFunc() BuildStoresFunc
Build() []metricsstore.MetricsWriter Build() []metricsstore.MetricsWriter
} }
// BuildStoreFunc function signature that is use to returns a list of metricsstore.MetricsStore // BuildStoresFunc function signature that is use to returns a list of metricsstore.MetricsStore
type BuildStoreFunc func(metricFamilies []generator.FamilyGenerator, type BuildStoresFunc func(metricFamilies []generator.FamilyGenerator,
expectedType interface{}, expectedType interface{},
listWatchFunc func(kubeClient clientset.Interface, ns string) cache.ListerWatcher, listWatchFunc func(kubeClient clientset.Interface, ns string) cache.ListerWatcher,
) []*metricsstore.MetricsStore ) []*metricsstore.MetricsStore