Skip to content

Commit

Permalink
feat: target enrichment rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Blackmore committed Feb 17, 2023
1 parent ad25c7e commit 5f2cc40
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 4 deletions.
4 changes: 4 additions & 0 deletions go/discovery_kit_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## UNRELEASED

- Support target enrichment rules.

## 1.0.0

- Empty release just to bump the version number to 1.0.0.
Expand Down
34 changes: 33 additions & 1 deletion go/discovery_kit_api/discovery_kit_api.go

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

29 changes: 29 additions & 0 deletions go/discovery_kit_api/discovery_kit_api_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2023 Steadybit GmbH

package discovery_kit_api

import (
Expand Down Expand Up @@ -104,6 +107,32 @@ func TestTargetDescription(t *testing.T) {
},
},
},
EnrichmentRules: Ptr([]TargetEnrichmentRule{
{
Src: SourceOrDestination{
Type: "k8s.deployment",
Selector: map[string]string{
"container.id": "${dest.container.id}",
},
},
Dest: SourceOrDestination{
Type: "container",
Selector: map[string]string{
"container.id": "${src.container.id}",
},
},
Attributes: []Attribute{
{
AggregationType: Any,
Name: "container.name",
},
{
AggregationType: All,
Name: "container.name",
},
},
},
}),
}
markAsUsed(t, v)
}
Expand Down
49 changes: 49 additions & 0 deletions openapi/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,50 @@ components:
required:
- columns
- orderBy
Attribute:
type: object
properties:
name:
type: string
aggregationType:
type: string
enum:
- any
- all
required:
- name
- aggregationType
SourceOrDestination:
type: object
properties:
type:
type: string
description: The source or destination target type.
selector:
type: object
description: To identify a source or a destination, we employ a mechanism similar to Kubernetes label selectors. When this instance represents a source, you can use the placeholder `${src.attribute}` to refer to target attributes of the destination. Note that you can use the placeholders `${src.attribute}` and `${dest.attribute}` respectively.
additionalProperties:
type: string
description: TODO
required:
- type
- selector
TargetEnrichmentRule:
type: object
properties:
src:
$ref: '#/components/schemas/SourceOrDestination'
dest:
$ref: '#/components/schemas/SourceOrDestination'
attributes:
type: array
items:
$ref: '#/components/schemas/Attribute'
uniqueItems: true
required:
- src
- dest
- attributes
TargetDescription:
type: object
description: "A definition of a target type and how it will be handled by the ui"
Expand All @@ -237,6 +281,11 @@ components:
pattern: '^data:.*$'
table:
$ref: '#/components/schemas/Table'
enrichmentRules:
type: array
items:
$ref: '#/components/schemas/TargetEnrichmentRule'
uniqueItems: true
required:
- id
- version
Expand Down
4 changes: 4 additions & 0 deletions typescript/discovery_kit_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## UNRELEASED

- Support target enrichment rules.

## 1.1.0

- Support restriction of discoveries to AWS agents.
Expand Down
5 changes: 4 additions & 1 deletion typescript/discovery_kit_api/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 Steadybit GmbH
// SPDX-FileCopyrightText: 2023 Steadybit GmbH

import { components } from './schemas';

Expand All @@ -16,6 +16,9 @@ export type DiscoveredTargets = components['schemas']['DiscoveredTargets'];
export type OrderBy = components['schemas']['OrderBy'];
export type Column = components['schemas']['Column'];
export type Table = components['schemas']['Table'];
export type TargetEnrichmentRule = components['schemas']['TargetEnrichmentRule'];
export type Attribute = components['schemas']['Attribute'];
export type SourceOrDestination = components['schemas']['SourceOrDestination'];
export type TargetDescription = components['schemas']['TargetDescription'];

export type DiscoveryListResponse = components['responses']['DiscoveryListResponse']['content']['application/json'];
Expand Down
30 changes: 28 additions & 2 deletions typescript/discovery_kit_api/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2022 Steadybit GmbH
// SPDX-FileCopyrightText: 2023 Steadybit GmbH

import {
AttributeDescriptions, DiscoveredTargets,
Expand Down Expand Up @@ -89,7 +89,33 @@ export const targetDescription: TargetDescription = {
direction: 'DESC'
}
]
}
},
enrichmentRules: [
{
src: {
type: 'k8s.deployment',
selector: {
"container.id": "${dest.container.id}",
}
},
dest: {
type: 'k8s.deployment',
selector: {
"container.id": "${dest.container.id}",
}
},
attributes: [
{
aggregationType: "all",
name: 'container.name'
},
{
aggregationType: "any",
name: 'container.name'
}
]
}
]
};

export const discoveryKitError: DiscoveryKitError = {
Expand Down
17 changes: 17 additions & 0 deletions typescript/discovery_kit_api/schemas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ export interface components {
columns: components['schemas']['Column'][];
orderBy: components['schemas']['OrderBy'][];
};
Attribute: {
name: string;
/** @enum {string} */
aggregationType: 'any' | 'all';
};
SourceOrDestination: {
/** @description The source or destination target type. */
type: string;
/** @description To identify a source or a destination, we employ a mechanism similar to Kubernetes label selectors. When this instance represents a source, you can use the placeholder `${src.attribute}` to refer to target attributes of the destination. Note that you can use the placeholders `${src.attribute}` and `${dest.attribute}` respectively. */
selector: { [key: string]: string };
};
TargetEnrichmentRule: {
src: components['schemas']['SourceOrDestination'];
dest: components['schemas']['SourceOrDestination'];
attributes: components['schemas']['Attribute'][];
};
/** @description A definition of a target type and how it will be handled by the ui */
TargetDescription: {
/** @description a global unique name of the target type */
Expand All @@ -119,6 +135,7 @@ export interface components {
/** @description An icon that is used to identify the targets in the ui. Needs to be a data-uri containing an image. */
icon?: string;
table: components['schemas']['Table'];
enrichmentRules?: components['schemas']['TargetEnrichmentRule'][];
};
};
responses: {
Expand Down

0 comments on commit 5f2cc40

Please sign in to comment.