Skip to content

Commit

Permalink
DEVPROD-13188: create admin setting for test selection URL (#8547)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimchelly authored Dec 12, 2024
1 parent 5d2d5aa commit 8c64ba6
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type Settings struct {
SleepSchedule SleepScheduleConfig `yaml:"sleep_schedule" bson:"sleep_schedule" json:"sleep_schedule" id:"sleep_schedule"`
Splunk SplunkConfig `yaml:"splunk" bson:"splunk" json:"splunk" id:"splunk"`
TaskLimits TaskLimitsConfig `yaml:"task_limits" bson:"task_limits" json:"task_limits" id:"task_limits"`
TestSelection TestSelectionConfig `yaml:"test_selection" bson:"test_selection" json:"test_selection" id:"test_selection"`
Triggers TriggerConfig `yaml:"triggers" bson:"triggers" json:"triggers" id:"triggers"`
Ui UIConfig `yaml:"ui" bson:"ui" json:"ui" id:"ui"`
Spawnhost SpawnHostConfig `yaml:"spawnhost" bson:"spawnhost" json:"spawnhost" id:"spawnhost"`
Expand Down
1 change: 1 addition & 0 deletions config_sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func NewConfigSections() ConfigSections {
&Settings{},
&JIRANotificationsConfig{},
&TaskLimitsConfig{},
&TestSelectionConfig{},
&TriggerConfig{},
&SpawnHostConfig{},
&TracerConfig{},
Expand Down
37 changes: 37 additions & 0 deletions config_test_selection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package evergreen

import (
"context"

"github.com/mongodb/anser/bsonutil"
"github.com/pkg/errors"
"go.mongodb.org/mongo-driver/bson"
)

// TestSelectionConfig represents the configuration of the test selection
// service.
type TestSelectionConfig struct {
URL string `bson:"url" json:"url" yaml:"url"`
}

var (
testSelectionURLKey = bsonutil.MustHaveTag(TestSelectionConfig{}, "URL")
)

func (c *TestSelectionConfig) SectionId() string { return "test_selection" }

func (c *TestSelectionConfig) Get(ctx context.Context) error {
return getConfigSection(ctx, c)
}

func (c *TestSelectionConfig) Set(ctx context.Context) error {
return errors.Wrapf(setConfigSection(ctx, c.SectionId(), bson.M{
"$set": bson.M{
testSelectionURLKey: c.URL,
}}), "updating config section '%s'", c.SectionId(),
)
}

func (c *TestSelectionConfig) ValidateAndDefault() error {
return nil
}
2 changes: 2 additions & 0 deletions rest/data/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (s *AdminDataSuite) TestSetAndGetSettings() {
s.ElementsMatch(testSettings.SleepSchedule.PermanentlyExemptHosts, settingsFromConnector.SleepSchedule.PermanentlyExemptHosts)
s.EqualValues(testSettings.Splunk.SplunkConnectionInfo.Channel, settingsFromConnector.Splunk.SplunkConnectionInfo.Channel)
s.EqualValues(testSettings.Ui.HttpListenAddr, settingsFromConnector.Ui.HttpListenAddr)
s.EqualValues(testSettings.TestSelection.URL, settingsFromConnector.TestSelection.URL)
s.EqualValues(testSettings.Tracer.Enabled, settingsFromConnector.Tracer.Enabled)
s.EqualValues(testSettings.Tracer.CollectorEndpoint, settingsFromConnector.Tracer.CollectorEndpoint)
s.EqualValues(testSettings.Tracer.CollectorInternalEndpoint, settingsFromConnector.Tracer.CollectorInternalEndpoint)
Expand Down Expand Up @@ -301,6 +302,7 @@ func (s *AdminDataSuite) TestSetAndGetSettings() {
s.ElementsMatch(testSettings.SleepSchedule.PermanentlyExemptHosts, settingsFromConnector.SleepSchedule.PermanentlyExemptHosts)
s.EqualValues(testSettings.Splunk.SplunkConnectionInfo.Channel, settingsFromConnector.Splunk.SplunkConnectionInfo.Channel)
s.EqualValues(testSettings.TaskLimits.MaxTasksPerVersion, settingsFromConnector.TaskLimits.MaxTasksPerVersion)
s.EqualValues(testSettings.TestSelection.URL, settingsFromConnector.TestSelection.URL)
s.EqualValues(testSettings.Ui.HttpListenAddr, settingsFromConnector.Ui.HttpListenAddr)
s.EqualValues(testSettings.Tracer.Enabled, settingsFromConnector.Tracer.Enabled)
s.EqualValues(testSettings.Tracer.CollectorEndpoint, settingsFromConnector.Tracer.CollectorEndpoint)
Expand Down
22 changes: 22 additions & 0 deletions rest/model/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func NewConfigModel() *APIAdminSettings {
SleepSchedule: &APISleepScheduleConfig{},
Splunk: &APISplunkConfig{},
TaskLimits: &APITaskLimitsConfig{},
TestSelection: &APITestSelectionConfig{},
Triggers: &APITriggerConfig{},
Ui: &APIUIConfig{},
Spawnhost: &APISpawnHostConfig{},
Expand Down Expand Up @@ -91,6 +92,7 @@ type APIAdminSettings struct {
SSHKeyPairs []APISSHKeyPair `json:"ssh_key_pairs,omitempty"`
Splunk *APISplunkConfig `json:"splunk,omitempty"`
TaskLimits *APITaskLimitsConfig `json:"task_limits,omitempty"`
TestSelection *APITestSelectionConfig `json:"test_selection,omitempty"`
Triggers *APITriggerConfig `json:"triggers,omitempty"`
Ui *APIUIConfig `json:"ui,omitempty"`
Spawnhost *APISpawnHostConfig `json:"spawnhost,omitempty"`
Expand Down Expand Up @@ -2801,6 +2803,26 @@ func (c *APITaskLimitsConfig) ToService() (interface{}, error) {
}, nil
}

type APITestSelectionConfig struct {
URL *string `json:"url"`
}

func (c *APITestSelectionConfig) BuildFromService(h interface{}) error {
switch v := h.(type) {
case evergreen.TestSelectionConfig:
c.URL = utility.ToStringPtr(v.URL)
return nil
default:
return errors.Errorf("programmatic error: expected test selection config but got type %T", h)
}
}

func (c *APITestSelectionConfig) ToService() (interface{}, error) {
return evergreen.TestSelectionConfig{
URL: utility.FromStringPtr(c.URL),
}, nil
}

type APIRuntimeEnvironmentsConfig struct {
BaseURL *string `json:"base_url"`
APIKey *string `json:"api_key"`
Expand Down
2 changes: 2 additions & 0 deletions rest/model/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func TestModelConversion(t *testing.T) {
assert.ElementsMatch(testSettings.SleepSchedule.PermanentlyExemptHosts, apiSettings.SleepSchedule.PermanentlyExemptHosts)
assert.EqualValues(testSettings.Splunk.SplunkConnectionInfo.Channel, utility.FromStringPtr(apiSettings.Splunk.SplunkConnectionInfo.Channel))
assert.EqualValues(testSettings.TaskLimits.MaxTasksPerVersion, utility.FromIntPtr(apiSettings.TaskLimits.MaxTasksPerVersion))
assert.EqualValues(testSettings.TestSelection.URL, utility.FromStringPtr(apiSettings.TestSelection.URL))
assert.EqualValues(testSettings.Triggers.GenerateTaskDistro, utility.FromStringPtr(apiSettings.Triggers.GenerateTaskDistro))
assert.EqualValues(testSettings.Ui.HttpListenAddr, utility.FromStringPtr(apiSettings.Ui.HttpListenAddr))
assert.Equal(testSettings.Spawnhost.SpawnHostsPerUser, *apiSettings.Spawnhost.SpawnHostsPerUser)
Expand Down Expand Up @@ -322,6 +323,7 @@ func TestModelConversion(t *testing.T) {
assert.ElementsMatch(testSettings.SleepSchedule.PermanentlyExemptHosts, apiSettings.SleepSchedule.PermanentlyExemptHosts)
assert.EqualValues(testSettings.Splunk.SplunkConnectionInfo.Channel, dbSettings.Splunk.SplunkConnectionInfo.Channel)
assert.EqualValues(testSettings.TaskLimits.MaxTasksPerVersion, dbSettings.TaskLimits.MaxTasksPerVersion)
assert.EqualValues(testSettings.TestSelection.URL, dbSettings.TestSelection.URL)
assert.EqualValues(testSettings.Triggers.GenerateTaskDistro, dbSettings.Triggers.GenerateTaskDistro)
assert.EqualValues(testSettings.Ui.HttpListenAddr, dbSettings.Ui.HttpListenAddr)
assert.EqualValues(testSettings.Spawnhost.SpawnHostsPerUser, dbSettings.Spawnhost.SpawnHostsPerUser)
Expand Down
1 change: 1 addition & 0 deletions rest/route/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (s *AdminRouteSuite) TestAdminRoute() {
s.ElementsMatch(testSettings.SleepSchedule.PermanentlyExemptHosts, settings.SleepSchedule.PermanentlyExemptHosts)
s.EqualValues(testSettings.Splunk.SplunkConnectionInfo.Channel, settings.Splunk.SplunkConnectionInfo.Channel)
s.EqualValues(testSettings.TaskLimits.MaxTasksPerVersion, settings.TaskLimits.MaxTasksPerVersion)
s.EqualValues(testSettings.TestSelection.URL, settings.TestSelection.URL)
s.EqualValues(testSettings.Ui.HttpListenAddr, settings.Ui.HttpListenAddr)

// test that invalid input errors
Expand Down
20 changes: 20 additions & 0 deletions service/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ <h2 class="modal-title">[[modalTitle]]</h2>
<li class="link" ng-click="scrollTo('newrelic')">New Relic</li>
<li class="link" ng-click="scrollTo('cedar')">Cedar</li>
<li class="link" ng-click="scrollTo('runtime_environments')">Runtime Environments</li>
<li class="link" ng-click="scrollTo('test_selection')">Test Selection</li>
<div>Background Processing</div>
<li class="link" ng-click="scrollTo('amboy')">Amboy</li>
<li class="link" ng-click="scrollTo('logger_config')">Logger Config</li>
Expand Down Expand Up @@ -1523,6 +1524,25 @@ <h2 class="modal-title">[[modalTitle]]</h2>
</md-card>
</section>

<section layout="row" flex>
<md-card flex=50 id="test_selection" style="height:auto">
<md-card-title>
<md-card-title-text>
<span>Test Selection</span>
</md-card-title-text>
<md-button ng-click="clearSection('test_selection')">
<i class="fa fa-trash"></i>
</md-button>
</md-card-title>
<md-card-content>
<md-input-container class="control" style="width:45%;">
<label>URL</label>
<input type="text" ng-model="Settings.test_selection.url">
</md-input-container>
</md-card-content>
</md-card>
</section>

<section layout="row" flex>
<md-card flex=50 id="amboy">
<md-card-title>
Expand Down
3 changes: 3 additions & 0 deletions testutil/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ func MockConfig() *evergreen.Settings {
Channel: "channel",
},
},
TestSelection: evergreen.TestSelectionConfig{
URL: "test_selection_url",
},
Triggers: evergreen.TriggerConfig{
GenerateTaskDistro: "distro",
},
Expand Down

0 comments on commit 8c64ba6

Please sign in to comment.