Skip to content

Commit

Permalink
Set IsArchive Flag In Factory
Browse files Browse the repository at this point in the history
Signed-off-by: Mahad Zaryab <[email protected]>
  • Loading branch information
mahadzaryab1 committed Nov 4, 2024
1 parent bbcdbd7 commit 6c1fd95
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/query/app/token_propagation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func runQueryService(t *testing.T, esURL string) *Server {
flagsSvc := flags.NewService(ports.QueryAdminHTTP)
flagsSvc.Logger = zaptest.NewLogger(t)

f := es.NewFactory(es.PrimaryNamespace)
f := es.NewFactory(false)
v, command := config.Viperize(f.AddFlags)
require.NoError(t, command.ParseFlags([]string{
"--es.tls.enabled=false",
Expand Down
15 changes: 11 additions & 4 deletions plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import (
)

const (
PrimaryNamespace = "es"
ArchiveNamespace = "es-archive"
primaryNamespace = "es"
archiveNamespace = "es-archive"
)

var ( // interface comformance checks
Expand Down Expand Up @@ -65,9 +65,16 @@ type Factory struct {
}

// NewFactory creates a new Factory.
func NewFactory(namespace string) *Factory {
func NewFactory(isArchive bool) *Factory {
var options *Options
if isArchive {
options = NewOptions(archiveNamespace)
options.Primary.IsArchive = true
} else {
options = NewOptions(primaryNamespace)
}
return &Factory{
Options: NewOptions(namespace),
Options: options,
newClientFn: config.NewClient,
tracer: otel.GetTracerProvider(),
}
Expand Down
16 changes: 8 additions & 8 deletions plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m *mockClientBuilder) NewClient(*escfg.Configuration, *zap.Logger, metrics
}

func TestElasticsearchFactory(t *testing.T) {
f := NewFactory(PrimaryNamespace)
f := NewFactory(false)
v, command := config.Viperize(f.AddFlags)
command.ParseFlags([]string{})
f.InitFromViper(v, zap.NewNop())
Expand All @@ -88,7 +88,7 @@ func TestElasticsearchFactory(t *testing.T) {
}

func TestElasticsearchTagsFileDoNotExist(t *testing.T) {
f := NewFactory(PrimaryNamespace)
f := NewFactory(false)
f.config = &escfg.Configuration{
Tags: escfg.TagsAsFields{
File: "fixtures/file-does-not-exist.txt",
Expand All @@ -103,7 +103,7 @@ func TestElasticsearchTagsFileDoNotExist(t *testing.T) {
}

func TestElasticsearchILMUsedWithoutReadWriteAliases(t *testing.T) {
f := NewFactory(ArchiveNamespace)
f := NewFactory(false)
f.config = &escfg.Configuration{
UseILM: true,
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func TestTagKeysAsFields(t *testing.T) {
}

func TestCreateTemplateError(t *testing.T) {
f := NewFactory(PrimaryNamespace)
f := NewFactory(false)
f.config = &escfg.Configuration{CreateIndexTemplates: true}
f.newClientFn = (&mockClientBuilder{createTemplateError: errors.New("template-error")}).NewClient
err := f.Initialize(metrics.NullFactory, zap.NewNop())
Expand All @@ -194,7 +194,7 @@ func TestCreateTemplateError(t *testing.T) {
}

func TestILMDisableTemplateCreation(t *testing.T) {
f := NewFactory(PrimaryNamespace)
f := NewFactory(false)
f.config = &escfg.Configuration{UseILM: true, UseReadWriteAliases: true, CreateIndexTemplates: true}
f.newClientFn = (&mockClientBuilder{createTemplateError: errors.New("template-error")}).NewClient
err := f.Initialize(metrics.NullFactory, zap.NewNop())
Expand All @@ -205,7 +205,7 @@ func TestILMDisableTemplateCreation(t *testing.T) {
}

func TestConfigureFromOptions(t *testing.T) {
f := NewFactory(ArchiveNamespace)
f := NewFactory(false)
o := &Options{
Primary: namespaceConfig{Configuration: escfg.Configuration{Servers: []string{"server"}}},
}
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestESStorageFactoryWithConfigError(t *testing.T) {
func TestPasswordFromFile(t *testing.T) {
defer testutils.VerifyGoLeaksOnce(t)
t.Run("primary client", func(t *testing.T) {
f := NewFactory(PrimaryNamespace)
f := NewFactory(false)
testPasswordFromFile(t, f, f.getClient, f.CreateSpanWriter)
})

Expand Down Expand Up @@ -388,7 +388,7 @@ func TestPasswordFromFileErrors(t *testing.T) {
pwdFile := filepath.Join(t.TempDir(), "pwd")
require.NoError(t, os.WriteFile(pwdFile, []byte("first password"), 0o600))

f := NewFactory(PrimaryNamespace)
f := NewFactory(false)
f.config = &escfg.Configuration{
Servers: []string{server.URL},
LogLevel: "debug",
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
nsConfig.namespace+suffixAdaptiveSamplingLookback,
nsConfig.AdaptiveSamplingLookback,
"How far back to look for the latest adaptive sampling probabilities")
if nsConfig.namespace == ArchiveNamespace {
if nsConfig.namespace == archiveNamespace {
flagSet.Bool(
nsConfig.namespace+suffixEnabled,
nsConfig.Enabled,
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (*Factory) getFactoryOfType(factoryType string) (storage.Factory, error) {
case cassandraStorageType:
return cassandra.NewFactory(), nil
case elasticsearchStorageType, opensearchStorageType:
return es.NewFactory(es.PrimaryNamespace), nil
return es.NewFactory(false), nil
case memoryStorageType:
return memory.NewFactory(), nil
case kafkaStorageType:
Expand Down
8 changes: 1 addition & 7 deletions plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@ func (s *ESStorageIntegration) esCleanUp(t *testing.T) {

func (*ESStorageIntegration) initializeESFactory(t *testing.T, allTagsAsFields bool, isArchive bool) *es.Factory {
logger := zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller()))
var namespace string
if isArchive {
namespace = es.ArchiveNamespace
} else {
namespace = es.PrimaryNamespace
}
f := es.NewFactory(namespace)
f := es.NewFactory(isArchive)
v, command := config.Viperize(f.AddFlags)
var args []string
if isArchive {
Expand Down

0 comments on commit 6c1fd95

Please sign in to comment.