Skip to content

Commit

Permalink
feat(inspect): api for retrieving service hostnames (#11865)
Browse files Browse the repository at this point in the history
## Motivation

We want to see hostnames of Mesh*Service in the Global CP.

## Implementation information

While we could add new KDSService to retrieve stats of a resource in
specific zones and then aggregate this an easier (less expensive to
execute, faster, don't depend on the zone) option is to calculate the
hostname. We have all the resources in global CP already (because
HostnameGenerator from zone is synced to global for visibility). It's
just a matter of relabeling properly.

## Supporting documentation

Fix #10618

---------

Signed-off-by: Jakub Dyszkiewicz <[email protected]>
  • Loading branch information
jakubdyszkiewicz authored Jan 10, 2025
1 parent a0e715c commit ad81fbf
Show file tree
Hide file tree
Showing 20 changed files with 621 additions and 22 deletions.
91 changes: 91 additions & 0 deletions api/openapi/specs/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,44 @@ paths:
$ref: '#/components/responses/BadRequest'
'500':
$ref: '#/components/responses/Internal'
/meshes/{mesh}/{serviceType}/{serviceName}/_hostnames:
get:
operationId: inspect-hostnames
summary: Returns hostnames for service
description: Returns hostnames for a service
tags: ["Inspect"]
parameters:
- in: path
name: mesh
example: default
schema:
type: string
required: true
description: The mesh the service is part of
- in: path
name: serviceType
example: meshservices
schema:
type: string
enum: [meshservices, meshmultizoneservices, meshexternalservices]
required: true
description: The type of the service
- in: path
name: serviceName
example: redis
schema:
type: string
required: true
description: The name of the service
responses:
'200':
$ref: '#/components/responses/InspectHostnamesResponse'
'400':
$ref: '#/components/responses/BadRequest'
'404':
$ref: "./common/error_schema.yaml#/components/responses/NotFound"
'500':
$ref: '#/components/responses/Internal'
components:
schemas:
Index:
Expand Down Expand Up @@ -438,6 +476,42 @@ components:
GlobalInsight:
allOf:
- $ref: '#/components/schemas/schemas-GlobalInsight'
InspectHostnames:
type: object
title: InspectHostnames
description: A list of hostnames
required: [total, items]
properties:
total:
type: integer
example: 200
items:
type: array
items:
$ref: '#/components/schemas/InspectHostname'
InspectHostname:
type: object
title: InspectHostname
description: An supported hostname along with the zones it exists in
required: [hostname, zones]
properties:
hostname:
type: string
description: Generated hostname
example: redis.redis-system.svc.east.mesh.local
zones:
type: array
items:
$ref: '#/components/schemas/InspectHostnameZone'
InspectHostnameZone:
type: object
title: InspectHostnameZone
description: A name of the zone in which the hostname is available
required: [name]
properties:
name:
type: string
example: east
responses:
IndexResponse:
description: A response for the index endpoint
Expand Down Expand Up @@ -481,6 +555,15 @@ components:
application/json:
schema:
$ref: '#/components/schemas/InspectRules'
InspectHostnamesResponse:
description: A response containing hostnames that match a service.
content:
application/json:
schema:
$ref: '#/components/schemas/InspectHostnames'
examples:
ResponseForDataplane:
$ref: '#/components/examples/InspectDataplanesForPolicyExample'
BadRequest:
description: Bad Request
content:
Expand Down Expand Up @@ -571,3 +654,11 @@ components:
name: dp-2
labels:
k8s.kuma.io/namespace: kuma-system
InspectHostnamesExample:
value:
total: 100
items:
- hostname: redis.redis-system.svc.east.mesh.local
zones:
- name: east
- name: west
31 changes: 31 additions & 0 deletions api/openapi/types/zz_generated.api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 121 additions & 21 deletions docs/generated/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,48 @@ paths:
$ref: '#/components/responses/BadRequest'
'500':
$ref: '#/components/responses/Internal'
/meshes/{mesh}/{serviceType}/{serviceName}/_hostnames:
get:
operationId: inspect-hostnames
summary: Returns hostnames for service
description: Returns hostnames for a service
tags:
- Inspect
parameters:
- in: path
name: mesh
example: default
schema:
type: string
required: true
description: The mesh the service is part of
- in: path
name: serviceType
example: meshservices
schema:
type: string
enum:
- meshservices
- meshmultizoneservices
- meshexternalservices
required: true
description: The type of the service
- in: path
name: serviceName
example: redis
schema:
type: string
required: true
description: The name of the service
responses:
'200':
$ref: '#/components/responses/InspectHostnamesResponse'
'400':
$ref: '#/components/responses/BadRequest'
'404':
$ref: '#/components/responses/NotFound'
'500':
$ref: '#/components/responses/Internal'
/meshes/{mesh}/meshaccesslogs/{name}:
get:
operationId: get-mal
Expand Down Expand Up @@ -2628,6 +2670,47 @@ components:
GlobalInsight:
allOf:
- $ref: '#/components/schemas/schemas-GlobalInsight'
InspectHostnames:
type: object
title: InspectHostnames
description: A list of hostnames
required:
- total
- items
properties:
total:
type: integer
example: 200
items:
type: array
items:
$ref: '#/components/schemas/InspectHostname'
InspectHostname:
type: object
title: InspectHostname
description: An supported hostname along with the zones it exists in
required:
- hostname
- zones
properties:
hostname:
type: string
description: Generated hostname
example: redis.redis-system.svc.east.mesh.local
zones:
type: array
items:
$ref: '#/components/schemas/InspectHostnameZone'
InspectHostnameZone:
type: object
title: InspectHostnameZone
description: A name of the zone in which the hostname is available
required:
- name
properties:
name:
type: string
example: east
InvalidParameters:
type: object
title: Invalid Parameters
Expand Down Expand Up @@ -2955,6 +3038,21 @@ components:
on.
value:
description: The value to be used within the operations.
NotFoundError:
allOf:
- $ref: '#/components/schemas/Error'
- type: object
properties:
status:
example: 404
title:
example: Not Found
type:
example: https://httpstatuses.com/404
instance:
example: kong:trace:1234567890
detail:
example: Not found
MeshAccessLogItem:
type: object
required:
Expand Down Expand Up @@ -3598,21 +3696,6 @@ components:
request should correct or be aware of.
items:
type: string
NotFoundError:
allOf:
- $ref: '#/components/schemas/Error'
- type: object
properties:
status:
example: 404
title:
example: Not Found
type:
example: https://httpstatuses.com/404
instance:
example: kong:trace:1234567890
detail:
example: Not found
MeshCircuitBreakerItem:
type: object
required:
Expand Down Expand Up @@ -13022,6 +13105,15 @@ components:
application/json:
schema:
$ref: '#/components/schemas/InspectRules'
InspectHostnamesResponse:
description: A response containing hostnames that match a service.
content:
application/json:
schema:
$ref: '#/components/schemas/InspectHostnames'
examples:
ResponseForDataplane:
$ref: '#/components/examples/InspectDataplanesForPolicyExample'
BadRequest:
description: Bad Request
content:
Expand All @@ -13034,6 +13126,12 @@ components:
application/problem+json:
schema:
$ref: '#/components/schemas/Error'
NotFound:
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/NotFoundError'
MeshAccessLogItem:
description: Successful response
content:
Expand All @@ -13057,12 +13155,6 @@ components:
next:
type: string
description: URL to the next page
NotFound:
description: Not Found
content:
application/problem+json:
schema:
$ref: '#/components/schemas/NotFoundError'
MeshCircuitBreakerItem:
description: Successful response
content:
Expand Down Expand Up @@ -13625,4 +13717,12 @@ components:
name: dp-2
labels:
k8s.kuma.io/namespace: kuma-system
InspectHostnamesExample:
value:
total: 100
items:
- hostname: redis.redis-system.svc.east.mesh.local
zones:
- name: east
- name: west

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ require (
go.opentelemetry.io/otel/metric v1.33.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e
golang.org/x/mod v0.22.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/term v0.27.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions pkg/api-server/endpoints_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ var _ = Describe("Endpoints", func() {
apiTest(inputFile, apiServer, resourceStore)
}, test.EntriesForFolder("resources/inspect/policies/_resources/dataplanes"))

DescribeTable("inspect for policies /meshes/{mesh}/{serviceType}/{policyName}/_hostnames", func(inputFile string) {
apiTest(inputFile, apiServer, resourceStore)
}, test.EntriesForFolder("resources/inspect/services/_resources/hostnames"))

DescribeTable("inspect dataplane rules /meshes/{mesh}/dataplanes/{dpName}/_rules", func(inputFile string) {
apiTest(inputFile, apiServer, resourceStore)
}, test.EntriesForFolder("resources/inspect/dataplanes/_rules"))
Expand Down
Loading

0 comments on commit ad81fbf

Please sign in to comment.