Relationships
Relationships associate two different configs. They help in visualizing the connection of a config above and below in a hierarchy. Example: A kubernetes pod is linked to a Deployment and ReplicaSet and also to the persistent volumes.
apiVersion: configs.flanksource.com/v1
kind: ScrapeConfig
metadata:
name: kubernetes-scraper
spec:
kubernetes:
- clusterName: local-kind-cluster
transform:
relationship:
# Link a service to a deployment
- filter: config_type == "Kubernetes::Service"
type:
value: 'Kubernetes::Deployment'
name:
expr: |
has(config.spec.selector) && has(config.spec.selector.name) ? config.spec.selector.name : ''
# Link Pods to PVCs
- filter: config_type == 'Kubernetes::Pod'
expr: |
config.spec.volumes.
filter(item, has(item.persistentVolumeClaim)).
map(item, {
"type": "Kubernetes::PersistentVolumeClaim",
"name": item.persistentVolumeClaim.claimName
}).
toJSON()
Relationship Config
This transformation function allows you to dynamically form relationships between two different config items using selectors.
Example: You can link a kubernetes deployment with the corresponding pods, or you can link AWS EC2 instances with the AWS Account. It's even possible to link two configs scraped by different scrape configs like: linking a Kubernetes Node in an EKS cluster to the EC2 instance.
Field | Description | Scheme | Required |
---|---|---|---|
filter | Specify the config item with which relationship should be formed | string | true |
expr | cel-expression that returns a list of relationship selector. | string | |
id | id of the config to link to | RelationshipLookup | |
name | name of the config to link to | RelationshipLookup | |
type | type of the config to link to | RelationshipLookup | |
agent | agent of the config to link to | RelationshipLookup | |
labels | Labels of the config to link to | RelationshipLookup |
expr
is an alternative, more flexible, way to define the selectors. Either use expr
or the other selector fields (id
, name
, type
, agent
, labels
) but not both.
RelationshipSelector
Field | Description | Scheme | Required |
---|---|---|---|
id | id of the config to link to | string | |
name | id of the config to link to | string | |
type | id of the config to link to | string | |
agent | id of the config to link to | string | |
labels | Labels of the config to link to | map[string]string |
Relationship Lookup
RelationshipLookup offers different ways to specify a lookup value
Field | Description | Scheme | Required |
---|---|---|---|
expr | Use an expression to get the value | string | |
value | Specify a static value | string | |
label | Get the value from a label | string |
Template Variables
Both the filter
and expr
in the relationship config & the expr
in relationship lookup receive the ScrapeResult
as its template variable.