-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ruben Vargas <[email protected]>
- Loading branch information
1 parent
1793c4a
commit 755aca5
Showing
9 changed files
with
209 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) 2021 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package rollover | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/crossdock/crossdock-go/assert" | ||
"github.com/jaegertracing/jaeger/cmd/es-rollover/app" | ||
"github.com/jaegertracing/jaeger/pkg/es/client" | ||
"github.com/jaegertracing/jaeger/pkg/es/client/mocks" | ||
) | ||
|
||
func TestRolloverAction(t *testing.T) { | ||
readIndices := []client.Index{ | ||
{ | ||
Index: "jaeger-read-span", | ||
Aliases: map[string]bool{ | ||
"jaeger-span-archive-write": true, | ||
}, | ||
}, | ||
} | ||
|
||
aliasToCreate := []client.Alias{{Index: "jaeger-read-span", Name: "jaeger-span-archive-read", IsWriteIndex: false}} | ||
tests := []struct { | ||
name string | ||
conditions string | ||
unmarshalErrExpected bool | ||
getJaegerIndicesErr error | ||
rolloverErr error | ||
createAliasErr error | ||
expectedError bool | ||
}{ | ||
{ | ||
name: "success", | ||
conditions: "{\"max_age\": \"2d\"}", | ||
expectedError: false, | ||
}, | ||
{ | ||
name: "get jaeger indices error", | ||
conditions: "{\"max_age\": \"2d\"}", | ||
expectedError: true, | ||
getJaegerIndicesErr: errors.New("unable to get indices"), | ||
}, | ||
{ | ||
name: "rollover error", | ||
conditions: "{\"max_age\": \"2d\"}", | ||
expectedError: true, | ||
rolloverErr: errors.New("unable to rollover"), | ||
}, | ||
{ | ||
name: "create alias error", | ||
conditions: "{\"max_age\": \"2d\"}", | ||
expectedError: true, | ||
createAliasErr: errors.New("unable to create alias"), | ||
}, | ||
{ | ||
name: "unmarshal conditions error", | ||
conditions: "{\"max_age\" \"2d\"},", | ||
unmarshalErrExpected: true, | ||
createAliasErr: errors.New("unable to create alias"), | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
indexClient := &mocks.MockIndexAPI{} | ||
|
||
rolloverAction := Action{ | ||
Config: Config{ | ||
Conditions: test.conditions, | ||
Config: app.Config{ | ||
Archive: true, | ||
}, | ||
}, | ||
IndicesClient: indexClient, | ||
} | ||
|
||
if !test.unmarshalErrExpected { | ||
if test.rolloverErr == nil { | ||
indexClient.On("GetJaegerIndices", "").Return(readIndices, test.getJaegerIndicesErr) | ||
if test.getJaegerIndicesErr == nil { | ||
indexClient.On("CreateAlias", aliasToCreate).Return(test.createAliasErr) | ||
} | ||
} | ||
indexClient.On("Rollover", "jaeger-span-archive-write", map[string]interface{}{"max_age": "2d"}).Return(test.rolloverErr) | ||
} | ||
|
||
err := rolloverAction.Do() | ||
if test.expectedError || test.unmarshalErrExpected { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
indexClient.AssertExpectations(t) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package client | ||
|
||
type IndexAPI interface { | ||
GetJaegerIndices(prefix string) ([]Index, error) | ||
DeleteIndices(indices []Index) error | ||
CreateIndex(index string) error | ||
CreateAlias(aliases []Alias) error | ||
DeleteAlias(aliases []Alias) error | ||
CreateTemplate(template, name string) error | ||
Rollover(rolloverTarget string, conditions map[string]interface{}) error | ||
} | ||
|
||
type ClusterAPI interface { | ||
Version() (uint, error) | ||
} | ||
|
||
type IndexManagementLifecycleAPI interface { | ||
Exists(name string) (bool, error) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2021 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2021 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mocks | ||
|
||
import ( | ||
"github.com/jaegertracing/jaeger/pkg/es/client" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
type MockIndexAPI struct { | ||
mock.Mock | ||
} | ||
|
||
func (c *MockIndexAPI) GetJaegerIndices(prefix string) ([]client.Index, error) { | ||
ret := c.Called(prefix) | ||
return ret.Get(0).([]client.Index), ret.Error(1) | ||
} | ||
func (c *MockIndexAPI) DeleteIndices(indices []client.Index) error { | ||
ret := c.Called(indices) | ||
return ret.Error(0) | ||
} | ||
func (c *MockIndexAPI) CreateIndex(index string) error { | ||
ret := c.Called(index) | ||
return ret.Error(0) | ||
} | ||
func (c *MockIndexAPI) CreateAlias(aliases []client.Alias) error { | ||
ret := c.Called(aliases) | ||
return ret.Error(0) | ||
} | ||
func (c *MockIndexAPI) DeleteAlias(aliases []client.Alias) error { | ||
ret := c.Called(aliases) | ||
return ret.Error(0) | ||
} | ||
func (c *MockIndexAPI) CreateTemplate(template, name string) error { | ||
ret := c.Called(template, name) | ||
return ret.Error(0) | ||
} | ||
func (c *MockIndexAPI) Rollover(rolloverTarget string, conditions map[string]interface{}) error { | ||
ret := c.Called(rolloverTarget, conditions) | ||
return ret.Error(0) | ||
} |