Skip to content

Commit

Permalink
[jaeger-v2] Add validation and comments to memory storage config (#5925)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
- Resolves #5923

## Description of the changes
- Implemented `Validate` method for `Configuration` struct for memory
storage
- Created [migration
doc](https://docs.google.com/document/d/1w3z2hhxXAMLbuWsyyigUUMNSfflw4uayUERqHf45Dks/edit?usp=sharing)
from v1 to v2

## How was this change tested?
- Added unit tests for the new method

## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [x] I have added unit tests for the new functionality
- [x] I have run lint and test steps successfully
  - for `jaeger`: `make lint test`
  - for `jaeger-ui`: `yarn lint` and `yarn test`

---------

Signed-off-by: Mahad Zaryab <mahadzaryab1@gmail.com>
Signed-off-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
  • Loading branch information
mahadzaryab1 and yurishkuro authored Sep 2, 2024
1 parent 7df6975 commit ad6af7a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
12 changes: 11 additions & 1 deletion plugin/storage/memory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@

package memory

// Configuration describes the options to customize the storage behavior
import "github.com/asaskevich/govalidator"

// Configuration describes the options to customize the storage behavior.
type Configuration struct {
// MaxTraces is the maximum amount of traces to store in memory.
// If multi-tenancy is enabled, this limit applies per tenant.
// Zero value (default) means no limit (Warning: memory usage will be unbounded).
MaxTraces int `mapstructure:"max_traces"`
}

func (c *Configuration) Validate() error {
_, err := govalidator.ValidateStruct(c)
return err
}
35 changes: 35 additions & 0 deletions plugin/storage/memory/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2024 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package memory

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestValidate_DoesNotReturnErrorWhenValid(t *testing.T) {
tests := []struct {
name string
config *Configuration
}{
{
name: "non-required fields not set",
config: &Configuration{},
},
{
name: "all fields are set",
config: &Configuration{
MaxTraces: 100,
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := test.config.Validate()
require.NoError(t, err)
})
}
}

0 comments on commit ad6af7a

Please sign in to comment.