Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-5398: Update UI server to include if v2 is enabled #20353

Merged
merged 2 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/20353.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
ui: adds V2CatalogEnabled to config that is passed to the ui
```
9 changes: 9 additions & 0 deletions agent/uiserver/ui_template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ func uiTemplateDataFromConfig(cfg *config.RuntimeConfig) (map[string]interface{}
uiCfg["metrics_provider_options"] = json.RawMessage(cfg.UIConfig.MetricsProviderOptionsJSON)
}

v2CatalogEnabled := false
for _, experiment := range cfg.Experiments {
if experiment == "resource-apis" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1/agent/self is an interesting endpoint 🤔 and the DebugConfig field seems to be completely undocumented on the consul apis page.

Does "enabled" here mean the DC has a V2 service registered or just that it has the permission to register one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is it's like a feature flag, not telling you that you actually have services registered. However, if you have this experiment enabled, requests to V1 catalog endpoints don't succeed.

v2CatalogEnabled = true
break
}
}

d := map[string]interface{}{
"ContentPath": cfg.UIConfig.ContentPath,
"ACLsEnabled": cfg.ACLsEnabled,
Expand All @@ -39,6 +47,7 @@ func uiTemplateDataFromConfig(cfg *config.RuntimeConfig) (map[string]interface{}
"LocalDatacenter": cfg.Datacenter,
"PrimaryDatacenter": cfg.PrimaryDatacenter,
"PeeringEnabled": cfg.PeeringEnabled,
"V2CatalogEnabled": v2CatalogEnabled,
}

// Also inject additional provider scripts if needed, otherwise strip the
Expand Down
48 changes: 42 additions & 6 deletions agent/uiserver/uiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
Expand Down Expand Up @@ -90,7 +91,8 @@ func TestUIServerIndex(t *testing.T) {
},
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
Expand All @@ -111,7 +113,8 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
Expand All @@ -132,7 +135,30 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
name: "v2 catalog enabled",
cfg: basicUIEnabledConfig(withV2CatalogEnabled()),
path: "/",
wantStatus: http.StatusOK,
wantContains: []string{"<!-- CONSUL_VERSION:"},
wantUICfgJSON: `{
"ACLsEnabled": false,
"HCPEnabled": false,
"LocalDatacenter": "dc1",
"PrimaryDatacenter": "dc1",
"ContentPath": "/ui/",
"PeeringEnabled": true,
"UIConfig": {
"hcp_enabled": false,
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
},
"V2CatalogEnabled": true
}`,
},
{
Expand All @@ -155,7 +181,8 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
Expand Down Expand Up @@ -187,7 +214,8 @@ func TestUIServerIndex(t *testing.T) {
"metrics_provider": "bar",
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
}
},
"V2CatalogEnabled": false
}`,
},
{
Expand Down Expand Up @@ -320,6 +348,12 @@ func withHCPEnabled() cfgFunc {
}
}

func withV2CatalogEnabled() cfgFunc {
return func(cfg *config.RuntimeConfig) {
cfg.Experiments = append(cfg.Experiments, "resource-apis")
}
}

func withPeeringDisabled() cfgFunc {
return func(cfg *config.RuntimeConfig) {
cfg.PeeringEnabled = false
Expand Down Expand Up @@ -466,6 +500,7 @@ func TestHandler_ServeHTTP_TransformIsEvaluatedOnEachRequest(t *testing.T) {
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
},
"V2CatalogEnabled": false,
"apple": "seeds"
}`
require.JSONEq(t, expected, extractUIConfig(t, rec.Body.String()))
Expand All @@ -492,6 +527,7 @@ func TestHandler_ServeHTTP_TransformIsEvaluatedOnEachRequest(t *testing.T) {
"metrics_proxy_enabled": false,
"dashboard_url_templates": null
},
"V2CatalogEnabled": false,
"apple": "plant"
}`
require.JSONEq(t, expected, extractUIConfig(t, rec.Body.String()))
Expand Down
8 changes: 8 additions & 0 deletions ui/packages/consul-ui/app/utils/get-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export default function (config = {}, win = window, doc = document) {
// reserve 1 for traffic that we can't manage
return 5;
}
case 'CONSUL_V2_CATALOG_ENABLED':
return operatorConfig.V2CatalogEnabled === 'undefined'
? false
: operatorConfig.V2CatalogEnabled;
}
};
const ui = function (key) {
Expand Down Expand Up @@ -244,6 +248,9 @@ export default function (config = {}, win = window, doc = document) {
case 'TokenSecretID':
prev['CONSUL_HTTP_TOKEN'] = value;
break;
case 'CONSUL_V2_CATALOG_ENABLE':
prev['CONSUL_V2_CATALOG_ENABLED'] = JSON.parse(value);
break;
default:
prev[key] = value;
}
Expand Down Expand Up @@ -295,6 +302,7 @@ export default function (config = {}, win = window, doc = document) {
case 'CONSUL_METRICS_PROXY_ENABLE':
case 'CONSUL_SERVICE_DASHBOARD_URL':
case 'CONSUL_BASE_UI_URL':
case 'CONSUL_V2_CATALOG_ENABLED':
case 'CONSUL_HTTP_PROTOCOL':
case 'CONSUL_HTTP_MAX_CONNECTIONS': {
// We allow the operator to set these ones via various methods
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/consul-ui/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ module.exports = function (environment, $ = process.env) {
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', ''),
V2CatalogEnabled: false,
},

// Static variables used in multiple places throughout the UI
Expand Down Expand Up @@ -122,6 +123,7 @@ module.exports = function (environment, $ = process.env) {
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', ''),
V2CatalogEnabled: env('CONSUL_V2_CATALOG_ENABLED', false),
},

'@hashicorp/ember-cli-api-double': {
Expand Down Expand Up @@ -176,6 +178,7 @@ module.exports = function (environment, $ = process.env) {
LocalDatacenter: env('CONSUL_DATACENTER_LOCAL', 'dc1'),
PrimaryDatacenter: env('CONSUL_DATACENTER_PRIMARY', 'dc1'),
APIPrefix: env('CONSUL_API_PREFIX', ''),
V2CatalogEnabled: env('CONSUL_V2_CATALOG_ENABLED', false),
},

'@hashicorp/ember-cli-api-double': {
Expand Down
2 changes: 1 addition & 1 deletion ui/packages/consul-ui/lib/startup/templates/body.html.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ ${
'CONSUL_HCP_ENABLE': {
name: 'consul-hcp',
default: ${config.operatorConfig.HCPEnabled}
}
},
}
);
</script>
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/consul-ui/node-tests/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test('config has the correct environment settings', function (t) {
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
V2CatalogEnabled: false,
},
},
{
Expand All @@ -49,6 +50,7 @@ test('config has the correct environment settings', function (t) {
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
V2CatalogEnabled: false,
},
},
{
Expand All @@ -67,6 +69,7 @@ test('config has the correct environment settings', function (t) {
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
V2CatalogEnabled: false,
},
},
{
Expand All @@ -82,6 +85,7 @@ test('config has the correct environment settings', function (t) {
LocalDatacenter: 'dc1',
PrimaryDatacenter: 'dc1',
APIPrefix: '',
V2CatalogEnabled: false,
},
},
].forEach(function (item) {
Expand Down
Loading