Skip to content

Commit

Permalink
Add ArchiveCapable Interface To Initialize Correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Jan 23, 2025
1 parent 1f809e9 commit 89ba32d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 24 deletions.
4 changes: 4 additions & 0 deletions plugin/configurable.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ type Configurable interface {
type Inheritable interface {
InheritSettingsFrom(other storage.Factory)
}

type ArchiveCapable interface {
IsArchiveCapable() bool
}
5 changes: 5 additions & 0 deletions plugin/storage/cassandra/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var ( // interface comformance checks
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
_ plugin.Inheritable = (*Factory)(nil)
_ plugin.ArchiveCapable = (*Factory)(nil)
)

// Factory implements storage.Factory for Cassandra backend.
Expand Down Expand Up @@ -289,3 +290,7 @@ func (f *Factory) InheritSettingsFrom(other storage.Factory) {
f.config.ApplyDefaults(&otherFactory.config)
}
}

func (f *Factory) IsArchiveCapable() bool {
return f.Options.NamespaceConfig.namespace == archiveStorageNamespace && f.Options.Enabled

Check warning on line 295 in plugin/storage/cassandra/factory.go

View check run for this annotation

Codecov / codecov/patch

plugin/storage/cassandra/factory.go#L294-L295

Added lines #L294 - L295 were not covered by tests
}
15 changes: 10 additions & 5 deletions plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ const (
)

var ( // interface comformance checks
_ storage.Factory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
_ plugin.Inheritable = (*Factory)(nil)
_ storage.Purger = (*Factory)(nil)
_ storage.Factory = (*Factory)(nil)
_ io.Closer = (*Factory)(nil)
_ plugin.Configurable = (*Factory)(nil)
_ plugin.Inheritable = (*Factory)(nil)
_ storage.Purger = (*Factory)(nil)
_ plugin.ArchiveCapable = (*Factory)(nil)
)

// Factory implements storage.Factory for Elasticsearch backend.
Expand Down Expand Up @@ -369,3 +370,7 @@ func (f *Factory) InheritSettingsFrom(other storage.Factory) {
f.config.ApplyDefaults(otherFactory.config)
}
}

func (f *Factory) IsArchiveCapable() bool {
return f.Options.Config.namespace == archiveNamespace && f.config.Enabled

Check warning on line 375 in plugin/storage/es/factory.go

View check run for this annotation

Codecov / codecov/patch

plugin/storage/es/factory.go#L374-L375

Added lines #L374 - L375 were not covered by tests
}
2 changes: 1 addition & 1 deletion plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
if nsConfig.namespace == archiveNamespace {
flagSet.Bool(
nsConfig.namespace+suffixEnabled,
nsConfig.Enabled,
false,
"Enable extra storage")
} else {
// MaxSpanAge is only relevant when searching for unarchived traces.
Expand Down
45 changes: 27 additions & 18 deletions plugin/storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,39 @@ func (*Factory) getArchiveFactoryOfType(factoryType string) (storage.Factory, er
}
}

// Initialize implements storage.Factory.
func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
f.metricsFactory = metricsFactory
initializeFactories := func(factories map[string]storage.Factory, role string) error {
for kind, factory := range factories {
mf := metricsFactory.Namespace(metrics.NSOptions{
Name: "storage",
Tags: map[string]string{
"kind": kind,
"role": role,
},
})
if err := factory.Initialize(mf, logger); err != nil {
return err
}

initializeFactory := func(kind string, factory storage.Factory, role string) error {
mf := metricsFactory.Namespace(metrics.NSOptions{
Name: "storage",
Tags: map[string]string{
"kind": kind,
"role": role,
},
})
return factory.Initialize(mf, logger)
}

for kind, factory := range f.factories {
if err := initializeFactory(kind, factory, "primary"); err != nil {
return err
}
return nil
}
if err := initializeFactories(f.factories, "primary"); err != nil {
return err

uninitializedArchiveFactories := make(map[string]struct{})
for kind, factory := range f.archiveFactories {
if archivable, ok := factory.(plugin.ArchiveCapable); ok && archivable.IsArchiveCapable() {
if err := initializeFactory(kind, factory, "primary"); err != nil {
uninitializedArchiveFactories[kind] = struct{}{}
}
}
}
if err := initializeFactories(f.archiveFactories, "archive"); err != nil {
return err

for kind := range uninitializedArchiveFactories {
delete(f.archiveFactories, kind)
}

f.publishOpts()
return nil
}
Expand Down

0 comments on commit 89ba32d

Please sign in to comment.