From ad6af7af8d27883eb4b802bf1aa09e6a14835bef Mon Sep 17 00:00:00 2001 From: Mahad Zaryab <43658574+mahadzaryab1@users.noreply.github.com> Date: Mon, 2 Sep 2024 17:44:13 -0400 Subject: [PATCH] [jaeger-v2] Add validation and comments to memory storage config (#5925) ## 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 Signed-off-by: Yuri Shkuro Co-authored-by: Yuri Shkuro --- plugin/storage/memory/config.go | 12 +++++++++- plugin/storage/memory/config_test.go | 35 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 plugin/storage/memory/config_test.go diff --git a/plugin/storage/memory/config.go b/plugin/storage/memory/config.go index a063c3c087c..5c2332b58cd 100644 --- a/plugin/storage/memory/config.go +++ b/plugin/storage/memory/config.go @@ -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 +} diff --git a/plugin/storage/memory/config_test.go b/plugin/storage/memory/config_test.go new file mode 100644 index 00000000000..c69c09ffd8b --- /dev/null +++ b/plugin/storage/memory/config_test.go @@ -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) + }) + } +}