Skip to content

Commit

Permalink
Merge pull request #1499 from fpetkovski/fix-multiwatcher
Browse files Browse the repository at this point in the history
Replace multiListerWatcher with independent listWatchers per namespace
  • Loading branch information
k8s-ci-robot committed Jul 14, 2021
2 parents 813c85a + 06dc134 commit 1d61fc1
Show file tree
Hide file tree
Showing 10 changed files with 467 additions and 533 deletions.
262 changes: 143 additions & 119 deletions internal/store/builder.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func main() {

storeBuilder.WithAllowDenyList(allowDenyList)

storeBuilder.WithGenerateStoreFunc(storeBuilder.DefaultGenerateStoreFunc())
storeBuilder.WithGenerateStoresFunc(storeBuilder.DefaultGenerateStoresFunc())

proc.StartReaper()

Expand Down
10 changes: 5 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func BenchmarkKubeStateMetrics(b *testing.B) {
builder.WithSharding(0, 1)
builder.WithContext(ctx)
builder.WithNamespaces(options.DefaultNamespaces)
builder.WithGenerateStoreFunc(builder.DefaultGenerateStoreFunc())
builder.WithGenerateStoresFunc(builder.DefaultGenerateStoresFunc())

l, err := allowdenylist.New(map[string]struct{}{}, map[string]struct{}{})
if err != nil {
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestFullScrapeCycle(t *testing.T) {
builder.WithEnabledResources(options.DefaultResources.AsSlice())
builder.WithKubeClient(kubeClient)
builder.WithNamespaces(options.DefaultNamespaces)
builder.WithGenerateStoreFunc(builder.DefaultGenerateStoreFunc())
builder.WithGenerateStoresFunc(builder.DefaultGenerateStoresFunc())

l, err := allowdenylist.New(map[string]struct{}{}, map[string]struct{}{})
if err != nil {
Expand Down Expand Up @@ -412,7 +412,7 @@ func TestShardingEquivalenceScrapeCycle(t *testing.T) {
unshardedBuilder.WithNamespaces(options.DefaultNamespaces)
unshardedBuilder.WithAllowDenyList(l)
unshardedBuilder.WithAllowLabels(map[string][]string{})
unshardedBuilder.WithGenerateStoreFunc(unshardedBuilder.DefaultGenerateStoreFunc())
unshardedBuilder.WithGenerateStoresFunc(unshardedBuilder.DefaultGenerateStoresFunc())

unshardedHandler := metricshandler.New(&options.Options{}, kubeClient, unshardedBuilder, false)
unshardedHandler.ConfigureSharding(ctx, 0, 1)
Expand All @@ -425,7 +425,7 @@ func TestShardingEquivalenceScrapeCycle(t *testing.T) {
shardedBuilder1.WithNamespaces(options.DefaultNamespaces)
shardedBuilder1.WithAllowDenyList(l)
shardedBuilder1.WithAllowLabels(map[string][]string{})
shardedBuilder1.WithGenerateStoreFunc(shardedBuilder1.DefaultGenerateStoreFunc())
shardedBuilder1.WithGenerateStoresFunc(shardedBuilder1.DefaultGenerateStoresFunc())

shardedHandler1 := metricshandler.New(&options.Options{}, kubeClient, shardedBuilder1, false)
shardedHandler1.ConfigureSharding(ctx, 0, 2)
Expand All @@ -438,7 +438,7 @@ func TestShardingEquivalenceScrapeCycle(t *testing.T) {
shardedBuilder2.WithNamespaces(options.DefaultNamespaces)
shardedBuilder2.WithAllowDenyList(l)
shardedBuilder2.WithAllowLabels(map[string][]string{})
shardedBuilder2.WithGenerateStoreFunc(shardedBuilder2.DefaultGenerateStoreFunc())
shardedBuilder2.WithGenerateStoresFunc(shardedBuilder2.DefaultGenerateStoresFunc())

shardedHandler2 := metricshandler.New(&options.Options{}, kubeClient, shardedBuilder2, false)
shardedHandler2.ConfigureSharding(ctx, 1, 2)
Expand Down
17 changes: 9 additions & 8 deletions pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package builder
import (
"context"

metricsstore "k8s.io/kube-state-metrics/v2/pkg/metrics_store"

"github.com/prometheus/client_golang/prometheus"
vpaclientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"

internalstore "k8s.io/kube-state-metrics/v2/internal/store"
ksmtypes "k8s.io/kube-state-metrics/v2/pkg/builder/types"
Expand Down Expand Up @@ -89,17 +90,17 @@ func (b *Builder) WithAllowLabels(l map[string][]string) {
b.internal.WithAllowLabels(l)
}

// WithGenerateStoreFunc configures a custom generate store function
func (b *Builder) WithGenerateStoreFunc(f ksmtypes.BuildStoreFunc) {
b.internal.WithGenerateStoreFunc(f)
// WithGenerateStoresFunc configures a custom generate store function
func (b *Builder) WithGenerateStoresFunc(f ksmtypes.BuildStoresFunc) {
b.internal.WithGenerateStoresFunc(f)
}

// DefaultGenerateStoreFunc returns default buildStore function
func (b *Builder) DefaultGenerateStoreFunc() ksmtypes.BuildStoreFunc {
return b.internal.DefaultGenerateStoreFunc()
// DefaultGenerateStoresFunc returns default buildStore function
func (b *Builder) DefaultGenerateStoresFunc() ksmtypes.BuildStoresFunc {
return b.internal.DefaultGenerateStoresFunc()
}

// Build initializes and registers all enabled stores.
func (b *Builder) Build() []cache.Store {
func (b *Builder) Build() []metricsstore.MetricsWriter {
return b.internal.Build()
}
14 changes: 8 additions & 6 deletions pkg/builder/types/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package types
import (
"context"

metricsstore "k8s.io/kube-state-metrics/v2/pkg/metrics_store"

"github.com/prometheus/client_golang/prometheus"
vpaclientset "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/client/clientset/versioned"
clientset "k8s.io/client-go/kubernetes"
Expand All @@ -38,17 +40,17 @@ type BuilderInterface interface {
WithKubeClient(c clientset.Interface)
WithVPAClient(c vpaclientset.Interface)
WithAllowDenyList(l AllowDenyLister)
WithGenerateStoreFunc(f BuildStoreFunc)
WithAllowLabels(l map[string][]string)
DefaultGenerateStoreFunc() BuildStoreFunc
Build() []cache.Store
WithGenerateStoresFunc(f BuildStoresFunc)
DefaultGenerateStoresFunc() BuildStoresFunc
Build() []metricsstore.MetricsWriter
}

// BuildStoreFunc function signature that is use to returns a cache.Store
type BuildStoreFunc func(metricFamilies []generator.FamilyGenerator,
// BuildStoresFunc function signature that is used to return a list of metricsstore.MetricsStore
type BuildStoresFunc func(metricFamilies []generator.FamilyGenerator,
expectedType interface{},
listWatchFunc func(kubeClient clientset.Interface, ns string) cache.ListerWatcher,
) cache.Store
) []*metricsstore.MetricsStore

// AllowDenyLister interface for AllowDeny lister that can allow or exclude metrics by there names
type AllowDenyLister interface {
Expand Down
202 changes: 0 additions & 202 deletions pkg/listwatch/listwatch.go

This file was deleted.

Loading

0 comments on commit 1d61fc1

Please sign in to comment.