Skip to content

Commit 552c986

Browse files
authored
Merge pull request #2692 from port-labs/PORTN-3230-aggregation-by-path
path filter of aggregation properties
2 parents e8a45a6 + fefda3d commit 552c986

File tree

2 files changed

+216
-0
lines changed

2 files changed

+216
-0
lines changed

docs/build-your-software-catalog/customize-integrations/configure-data-model/setup-blueprint/properties/aggregation-property.md

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,222 @@ Coming soon...
902902

903903
</Tabs>
904904

905+
### Path Filter
906+
907+
The `pathFilter` option lets you control which entities are included in your aggregation calculation based on their relationship path from the source entity. This is useful for complex relationship chains, where you may want to aggregate data only from entities connected through specific paths.
908+
909+
When a `pathFilter` is defined, Port will include only entities that can be reached through the exact relationship path you specify.
910+
911+
- **Forwards path →**
912+
Following relations forwards, from the source of a relation to its target (e.g., from a repository to its services).
913+
- **Backwards path ←**
914+
Following relations backwards, from the target of a relation to its source (e.g., from a service back to its repository).
915+
916+
**Structure**
917+
918+
| Field | Description |
919+
|---------------------------|----------------------------------------------------------------------------------------------------------------------|
920+
| `pathFilter.path` | An array containing the full path of relation identifiers to traverse. |
921+
| `pathFilter.fromBlueprint` | *(Optional)* The blueprint to start the path traversal from. Can be the target blueprint or omitted. If omitted, traversal starts from the source blueprint. |
922+
923+
924+
**For forwards paths**
925+
926+
```json showLineNumbers
927+
{
928+
"pathFilter": [
929+
{
930+
"path": ["relation1", "relation2", "relation3"]
931+
}
932+
]
933+
}
934+
```
935+
936+
**For backwards paths**
937+
938+
```json showLineNumbers
939+
{
940+
"pathFilter": [
941+
{
942+
"path": ["relation1", "relation2", "relation3"],
943+
"fromBlueprint": "{{targetBlueprint}}"
944+
}
945+
]
946+
}
947+
```
948+
949+
#### Examples
950+
951+
Suppose you have the following data model:
952+
953+
<img src='/img/software-catalog/blueprint/pathFilterDiagramExample.png' width='90%' border='1px' />
954+
<br></br>
955+
<br></br>
956+
957+
<Tabs groupId="path-filter-examples" defaultValue="api" values={[
958+
{label: "API", value: "api"},
959+
{label: "Terraform", value: "tf"}
960+
]}>
961+
962+
<TabItem value="api">
963+
964+
**Example 1: Standard Path Filter - forwards path**
965+
966+
Count how many deployments are directly related to a cluster:
967+
968+
```json
969+
{
970+
"identifier": "cluster",
971+
"title": "Cluster",
972+
"aggregationProperties": {
973+
"deploymentCount": {
974+
"title": "Deployment Count",
975+
"target": "deployment",
976+
"pathFilter": [
977+
{
978+
"path": ["deployments_relation"]
979+
}
980+
],
981+
"calculationSpec": {
982+
"calculationBy": "entities",
983+
"func": "count"
984+
}
985+
}
986+
}
987+
}
988+
```
989+
990+
The `pathFilter` with `"path": ["deployments_relation"]` counts deployments that are directly related to the cluster through the `deployments_relation` relation.
991+
992+
**Example 2: Using fromBlueprint - backwards path**
993+
994+
Count how many clusters are related to a deployment:
995+
996+
```json
997+
{
998+
"identifier": "deployment",
999+
"title": "Deployment",
1000+
"aggregationProperties": {
1001+
"clusterCount": {
1002+
"title": "Cluster Count",
1003+
"target": "cluster",
1004+
"pathFilter": [
1005+
{
1006+
"path": ["deployments_relation"],
1007+
"fromBlueprint": "cluster"
1008+
}
1009+
],
1010+
"calculationSpec": {
1011+
"calculationBy": "entities",
1012+
"func": "count"
1013+
}
1014+
}
1015+
}
1016+
}
1017+
```
1018+
1019+
The `fromBlueprint: "cluster"` specifies that the path traversal should start from the cluster blueprint (the target), then follow the path backwards through `deployments_relation` to deployment.
1020+
1021+
</TabItem>
1022+
1023+
<TabItem value="tf">
1024+
1025+
**Example 1: Standard Path Filter - forwards path**
1026+
1027+
Count how many deployments are directly related to a cluster:
1028+
1029+
```hcl
1030+
resource "port_blueprint" "cluster_blueprint" {
1031+
identifier = "cluster"
1032+
title = "Cluster"
1033+
relations = {
1034+
"deployments_relation" = {
1035+
title = "Deployments"
1036+
target = port_blueprint.deployment_blueprint.identifier
1037+
}
1038+
}
1039+
}
1040+
1041+
resource "port_blueprint" "deployment_blueprint" {
1042+
identifier = "deployment"
1043+
title = "Deployment"
1044+
}
1045+
1046+
resource "port_aggregation_properties" "cluster_aggregation_properties" {
1047+
blueprint_identifier = port_blueprint.cluster_blueprint.identifier
1048+
properties = {
1049+
deployment_count = {
1050+
target_blueprint_identifier = port_blueprint.deployment_blueprint.identifier
1051+
title = "Deployment Count"
1052+
icon = "Terraform"
1053+
description = "Deployment Count"
1054+
path_filter = [
1055+
{
1056+
path = ["deployments_relation"]
1057+
}
1058+
]
1059+
method = {
1060+
count_entities = true
1061+
}
1062+
}
1063+
}
1064+
}
1065+
```
1066+
1067+
The `path = ["deployments_relation"]` counts deployments that are directly related to the cluster through the `deployments_relation` relation.
1068+
1069+
**Example 2: Using fromBlueprint - backwards path**
1070+
1071+
Count how many clusters are related to a deployment:
1072+
1073+
```hcl
1074+
resource "port_blueprint" "deployment_blueprint" {
1075+
identifier = "deployment"
1076+
title = "Deployment"
1077+
}
1078+
1079+
resource "port_blueprint" "cluster_blueprint" {
1080+
identifier = "cluster"
1081+
title = "Cluster"
1082+
relations = {
1083+
"deployments_relation" = {
1084+
title = "Deployments"
1085+
target = port_blueprint.deployment_blueprint.identifier
1086+
}
1087+
}
1088+
}
1089+
1090+
resource "port_aggregation_properties" "deployment_aggregation_properties" {
1091+
blueprint_identifier = port_blueprint.deployment_blueprint.identifier
1092+
properties = {
1093+
cluster_count = {
1094+
target_blueprint_identifier = port_blueprint.cluster_blueprint.identifier
1095+
title = "Cluster Count"
1096+
icon = "Terraform"
1097+
description = "Cluster Count"
1098+
path_filter = [
1099+
{
1100+
path = ["deployments_relation"]
1101+
from_blueprint = "cluster"
1102+
}
1103+
]
1104+
method = {
1105+
count_entities = true
1106+
}
1107+
}
1108+
}
1109+
}
1110+
```
1111+
1112+
The `from_blueprint = "cluster"` specifies that the path traversal should start from the cluster blueprint (the target), then follow the path backwards through `deployments_relation` to deployment.
1113+
1114+
</TabItem>
1115+
1116+
</Tabs>
1117+
1118+
:::tip Path Filter Performance
1119+
Path filters can affect the performance of aggregation calculations. In general, shorter and more direct paths perform better than long or complex multi-hop paths.
1120+
:::
9051121

9061122
## Limitations
9071123

45.4 KB
Loading

0 commit comments

Comments
 (0)