From 206e414908e576ded54ab04060dd55d3876eeebb Mon Sep 17 00:00:00 2001 From: John Cowen Date: Wed, 26 May 2021 17:52:25 +0100 Subject: [PATCH] ui: Unix Domain Socket support (#10287) This commit adds UI support for Unix Domain Sockets for upstream and downstreams (see #9981 and #10252) --- .changelog/10287.txt | 3 + .../consul/service-instance/list/index.hbs | 9 +++ .../consul/upstream-instance/list/index.hbs | 62 ++++++++++++++----- .../consul-ui/app/models/service-instance.js | 1 + .../styles/components/icon-definition.scss | 3 + .../consul-ui/mock-api/v1/catalog/connect/_ | 10 +++ .../consul-ui/mock-api/v1/health/service/_ | 28 ++++++++- 7 files changed, 97 insertions(+), 19 deletions(-) create mode 100644 .changelog/10287.txt diff --git a/.changelog/10287.txt b/.changelog/10287.txt new file mode 100644 index 0000000000..d379f9c636 --- /dev/null +++ b/.changelog/10287.txt @@ -0,0 +1,3 @@ +```release-note:feature +ui: Add Unix Domain Socket support +``` diff --git a/ui/packages/consul-ui/app/components/consul/service-instance/list/index.hbs b/ui/packages/consul-ui/app/components/consul/service-instance/list/index.hbs index a47ebfa471..eca61b81fa 100644 --- a/ui/packages/consul-ui/app/components/consul/service-instance/list/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/service-instance/list/index.hbs @@ -62,6 +62,15 @@ as |item index|> {{/if}} +{{else if item.Service.SocketPath}} +
+
+ Socket Path +
+
+ {{item.Service.SocketPath}} +
+
{{/if}} diff --git a/ui/packages/consul-ui/app/components/consul/upstream-instance/list/index.hbs b/ui/packages/consul-ui/app/components/consul/upstream-instance/list/index.hbs index 15b8927c43..df4d2391c8 100644 --- a/ui/packages/consul-ui/app/components/consul/upstream-instance/list/index.hbs +++ b/ui/packages/consul-ui/app/components/consul/upstream-instance/list/index.hbs @@ -37,23 +37,53 @@ {{/if}} - {{#if (gt item.LocalBindPort 0)}} -{{#let (concat (or item.LocalBindAddress '127.0.0.1') ':' item.LocalBindPort) as |combinedAddress|}} -
-
- - Address - -
-
- - {{combinedAddress}} -
-
+ {{#if item.LocalBindSocketPath}} +{{#let (if item.LocalBindSocketMode + (hash + label=(concat '(Local bind mode)') + value=(concat '(Mode:' item.LocalBindSocketMode ')') + ) + (hash + label="" + value="" + ) + ) +as |mode|}} +
+
+ + Local bind socket {{mode.label}} + +
+
+ + {{item.LocalBindSocketPath}} +
+
{{/let}} + {{else}} + {{#if (gt item.LocalBindPort 0)}} + {{#let (concat (or item.LocalBindAddress '127.0.0.1') ':' item.LocalBindPort) as |combinedAddress|}} +
+
+ + Address + +
+
+ + {{combinedAddress}} +
+
+ {{/let}} + {{/if}} + {{/if}} diff --git a/ui/packages/consul-ui/app/models/service-instance.js b/ui/packages/consul-ui/app/models/service-instance.js index 85c88d9717..edff290b29 100644 --- a/ui/packages/consul-ui/app/models/service-instance.js +++ b/ui/packages/consul-ui/app/models/service-instance.js @@ -45,6 +45,7 @@ export default class ServiceInstance extends Model { // If the ID is blank fallback to the Service.Service (the Name) @or('Service.{ID,Service}') ID; @or('Service.Address', 'Node.Service') Address; + @attr('string') SocketPath; @alias('Service.Tags') Tags; @alias('Service.Meta') Meta; diff --git a/ui/packages/consul-ui/app/styles/components/icon-definition.scss b/ui/packages/consul-ui/app/styles/components/icon-definition.scss index 2259a0508f..0afcdb2941 100644 --- a/ui/packages/consul-ui/app/styles/components/icon-definition.scss +++ b/ui/packages/consul-ui/app/styles/components/icon-definition.scss @@ -32,6 +32,9 @@ %icon-definition.address dt::before { @extend %with-public-default-mask, %as-pseudo; } +%icon-definition.socket dt::before { + @extend %with-port-mask, %as-pseudo; +} %icon-definition.mesh dt::before { @extend %with-mesh-mask, %as-pseudo; } diff --git a/ui/packages/consul-ui/mock-api/v1/catalog/connect/_ b/ui/packages/consul-ui/mock-api/v1/catalog/connect/_ index f25031c005..983d8ad975 100644 --- a/ui/packages/consul-ui/mock-api/v1/catalog/connect/_ +++ b/ui/packages/consul-ui/mock-api/v1/catalog/connect/_ @@ -36,6 +36,9 @@ ${typeof location.search.ns !== 'undefined' ? ` "ServicePort": ${fake.random.number({min: 21000, max: 21255})}, "ServiceEnableTagOverride": false, "ServiceProxy": { + "Config": { + "protocol": "http" + }, "Expose": { "Checks": true, "Paths": [ @@ -50,15 +53,22 @@ ${range(env('CONSUL_EXPOSED_COUNT', 3)).map((i) => ` ] }, "Mode": "${fake.helpers.randomize(['', 'direct', 'transparent'])}", + "TransparentProxy": {}, "DestinationServiceName": "${location.pathname.slice(4)}" ${ location.pathname.slice(4) === "service-0" ? ` , "DestinationServiceID": "${location.pathname.slice(4)}-with-id", +${ fake.random.number({min: 1, max: 10}) > 2 ? ` "LocalServiceAddress": "${fake.internet.ip()}", "LocalServicePort": ${fake.random.number({min: 0, max: 65535})} +` : ` + "LocalServiceSocketMode": "0600", + "LocalServiceSocketPath": "/${fake.lorem.words(fake.random.number({min: 1, max: 5})).split(' ').join('/')}${fake.random.boolean() ? fake.system.fileName() : ''}" +` } ` : ``} }, + "ServiceSocketPath": "", "ServiceProxyDestination": "${location.pathname.slice(4)}", "ServiceWeights": { "Passing": 1, diff --git a/ui/packages/consul-ui/mock-api/v1/health/service/_ b/ui/packages/consul-ui/mock-api/v1/health/service/_ index 468f9f25da..cca5b7d8bc 100644 --- a/ui/packages/consul-ui/mock-api/v1/health/service/_ +++ b/ui/packages/consul-ui/mock-api/v1/health/service/_ @@ -18,7 +18,7 @@ const proxy = service.indexOf('-proxy') const sidecar = service.indexOf('-sidecar-proxy') const id = (proxy !== -1 ? service.slice(0, -6) + '-with-id-proxy' : service + '-with-id'); - let kind = ''; + let kind = ''; switch(true) { case service.endsWith('-mesh-gateway'): kind = 'mesh-gateway'; @@ -71,21 +71,38 @@ ${typeof location.search.ns !== 'undefined' ? ` ) } ], + "Weights": { + "Passing": 1, + "Warning": 1 + }, ${ fake.random.number({min: 1, max: 10}) > 2 ? ` "Meta": { "consul-dashboard-url": "${fake.internet.protocol()}://${fake.internet.domainName()}/?id={{Service}}", "external-source": "${fake.helpers.randomize(['consul', 'nomad', 'terraform', 'kubernetes', 'aws', ''])}" }, -` : `` } +` : ` + "Meta": null, +` } +${ false ? ` "Address":"${fake.internet.ip()}", "Port":${fake.random.number({min: 0, max: 65535})}, +` : ` + "Address":"", + "SocketPath": "/${fake.lorem.words(fake.random.number({min: 1, max: 5})).split(' ').join('/')}${fake.random.boolean() ? fake.system.fileName() : ''}", +` } + "Connect": {}, ${kind !== '' ? ` "Kind": "${kind}", ` : `` } "Proxy": { ${proxy !== -1 && sidecar === -1 ? ` "DestinationServiceName": "${service.substr(0, proxy)}", -` : ``} +` : ` + "Expose": {}, + "MeshGateway": {}, + "Mode": "", + "TransparentProxy": "" +`} ${sidecar !== -1 ? ` "DestinationServiceName": "${service.substr(0, sidecar)}", "DestinationServiceID": "${service.substr(0, sidecar)}-ID", @@ -113,8 +130,13 @@ ${range(env('CONSUL_EXPOSED_COUNT', 3)).map((i) => ` "DestinationName": "${fake.hacker.noun()}", "DestinationNamespace": "${fake.hacker.noun()}", "DestinationType": "${fake.helpers.randomize(['service', 'prepared_query'])}", +${ false ? ` "LocalBindAddress": "${fake.internet.ip()}", "LocalBindPort": ${fake.random.number({min: 0, max: 65535})} +` : ` + "LocalBindSocketMode": "0600", + "LocalBindSocketPath": "/${fake.lorem.words(fake.random.number({min: 1, max: 5})).split(' ').join('/')}${fake.random.boolean() ? fake.system.fileName() : ''}" +` } } `)} ]