Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create guide explaining how to connect OpenCost with AWS and Argo CD K8 resource #1397

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Guides",
"position": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
sidebar_position: 1
title: Connect Opencost Cloud Cost with ArgoCD/K8 resource in Port
---

import PortTooltip from "/src/components/tooltip/tooltip.jsx"

# Connect Opencost Cloud Cost with ArgoCD/K8 resource in Port

This guide demonstrates how to link OpenCost cloud cost data with your ArgoCD K8 resources within Port, enabling you to gain insights into the cost breakdown of your infrastructure and applications.

lordsarcastic marked this conversation as resolved.
Show resolved Hide resolved
## Use Case Examples:
- Cost Attribution: Determine which Kubernetes resource contribute the most to your overall cloud costs.
- Budget Management: Track the costs of individual pods or clusters against your budget allocations.
- Anomaly Detection: Identify unusual spikes in resource costs and investigate potential causes.
- Optimization Opportunities: Pinpoint resources that are underutilized or overprovisioned, potentially leading to cost savings.

:::


## Prerequisites
- This guide assumes you have a Port account and that you have finished the [onboarding process](/quickstart).
- Ensure you have [Port's Opencost integration installed and configured in your environment](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost).
- Ensure you have [Port's ArgoCD integration installed and configured in your environment](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/argocd/).


## Create the ArgoCD K8 relation

With Opencost and ArgoCD installed, you should see some blueprints created by both integrations.

Now that Port is synced with our ArgoCD and Opencost resources, let's map the Opencost Resource Allocations to the ArgoCD K8 resource.

First, we will need to create a [relation](/build-your-software-catalog/customize-integrations/configure-data-model/relate-blueprints/relate-blueprints.md) between our `argocdKubernetesResource` and the corresponding `openCostResourceAllocation`.

1. Head back to the [Builder](https://app.getport.io/settings/data-model), choose the `Kubernetes Resource

` <PortTooltip id="blueprint">blueprint</PortTooltip>, and click on `New relation`:

<img src='/img/build-your-software-catalog/sync-data-to-catalog/argocd/newRelationMapping.png' width='60%' border='1px' />

<br/><br/>

2. Fill out the form like this, then click `Create`:

<img src='/img/build-your-software-catalog/sync-data-to-catalog/argocd/createRelation.png' width='60%' border='1px' />

<br/><br/>


Now that the <PortTooltip id="blueprint">blueprints</PortTooltip> are related, we need to assign the relevant ArgoCD Kubernetes resource to each of our Opencost Resource Allocation. This can be done by adding some mapping logic. Go to your [data sources page](https://app.getport.io/settings/data-sources), and click on your ArgoCD integration

Under the `resources` key, locate the Kubernetes block and replace it with the following YAML block to map ArgoCD Kubernetes Resource to the respective Opencost Allocation Resource. Then click `Save & Resync`:

<details>
<summary><b>Relation mapping (click to expand)</b></summary>

```yaml showLineNumbers
- kind: managed-resource
selector:
query: "true"
port:
entity:
mappings:
identifier: .__application.metadata.uid + "-" + .kind + "-" + .name
title: .__application.metadata.name + "-" + .kind + "-" + .name
blueprint: '"argocdKubernetesResource"'
properties:
kind: .kind
namespace: .namespace
version: .resourceVersion
annotations: .liveState | fromjson | .metadata.annotations
labels: .liveState | fromjson | .metadata.labels
relations:
application: .__application.metadata.uid
image: 'if .kind == "Deployment" then .liveState | fromjson | .spec.template.spec.containers[0].image else null end'
openCostResourceAllocation: .name
```

</details>

:::tip Mapping explanation
The configuration mapping above maps `openCostResourceAllocation` using the `name` property of the Kubernetes resource since Opencost Resource Allocation have their identifiers as the name of the Kubernetes resource

:::

<img src='/img/build-your-software-catalog/sync-data-to-catalog/argocd/argoCDToOpencostRelation.png' border='1px' />


More relevant guides and examples:
- [Port's Opencost integration](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost)
- [Port's ArgoCD integration](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/argocd/)


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Opencost",
"position": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Guides",
"position": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
sidebar_position: 1
title: Connect Opencost Cloud Cost with AWS Resource in Port
---

import PortTooltip from "/src/components/tooltip/tooltip.jsx"

# Connect Opencost Clou- d Cost with AWS Resource in Port

This guide will show you how to connect an Opencost cloudcost resource with an AWS resource in Port to analyze your cloud cost allocation.

## Use Case Examples:

- Cost Attribution: Determine which AWS resources (EC2 instances, RDS databases, etc.) contribute the most to your overall cloud costs.
- Budget Management: Track the costs of individual resources or groups of resources against your budget allocations.
- Anomaly Detection: Identify unusual spikes in resource costs and investigate potential causes.
- Optimization Opportunities: Pinpoint resources that are underutilized or overprovisioned, potentially leading to cost savings.

:::

## Prerequisites
- This guide assumes you have a Port account and that you have finished the [onboarding process](/quickstart).
- Ensure you have [Port's Opencost integration installed and configured in your environment](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost).
- Ensure you have [Port's AWS integration installed and configured in your environment](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/cloud-providers/aws/installations/installation). This guide does not support the [deprecated AWS Exporter integration](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/cloud-providers/aws/aws-exporter/)


## Create the Opencost Cloudcost relation

With Opencost and AWS integrations installed, you should see some blueprints created by both integrations

Now that Port is synced with our AWS and Opencost resources, let's map the Opencost Cloudcost to the AWS Cloud Resources.

First, we will need to create a [relation](/build-your-software-catalog/customize-integrations/configure-data-model/relate-blueprints/relate-blueprints.md) between our `openCostCloudcost` and the corresponding `cloudResource`.

1. Head back to the [Builder](https://app.getport.io/settings/data-model), choose the `Opencost Cloudcost` <PortTooltip id="blueprint">blueprint</PortTooltip>, and click on `New relation`:

<img src='/img/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost/guides/newRelationOpenCost.png' width='60%' border='1px' />

<br/><br/>

2. Fill out the form like this, then click `Create`:

<img src='/img/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost/guides/createNewRelationOpencost.png' width='60%' border='1px' />

<br/><br/>


Now that the <PortTooltip id="blueprint">blueprints</PortTooltip> are related, we need to assign the relevant Opencost Cloudcost to each of our AWS Cloud Resource. This can be done by adding some mapping logic. Go to your [data sources page](https://app.getport.io/settings/data-sources), and click on your Opencost integration:

<img src='/img/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost/guides/datasourcesOpencost.png' border='1px' />

<br/><br/>

Under the `resources` key, locate the Cloudcost block and replace it with the following YAML block to map Opencost Cloudcost to the respective AWS Cloud Resource. Then click `Save & Resync`:

<details>
<summary><b>Relation mapping (click to expand)</b></summary>

```yaml showLineNumbers
- kind: cloudcost
selector:
query: .properties.providerID
aggregate: providerID
accumulate: week
window: week
port:
entity:
mappings:
identifier: .properties.providerID
title: .properties.providerID
blueprint: '"openCostCloudcost"'
properties:
startDate: .window.start
endDate: .window.end
listCost: .listCost.cost
netCost: .netCost.cost
amortizedNetCost: .amortizedNetCost.cost
invoicedCost: .invoicedCost.cost
amortizedCost: .amortizedCost.cost
relations:
awsCloudResource: .properties.providerID
```

</details>

:::tip Mapping explanation
The configuration mapping above ingests cloud cost data with selector properties designed to retrieve the AWS resource's ID

- `query: .properties.providerID` ensures that only entities with a providerID are ingested
- `aggregate: providerID` aggregates data by provider ID (AWS ARN) which ensures that entities are mapped to their respective AWS resource
- `accumulate: week` defines the step size which accumulates data week by week
- `window: week` grabs data for the past one week

For the `awsCloudCost` relation, we extract the resource ID from the Provider ID of the cloudcost information. Therefore, each Cloudcost entity will be mapped to their respective AWS resource.
By following these steps, you can seamlessly connect Opencost Cloudcost data with its respective AWS resources.

:::

<img src='/img/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost/guides/awsToCloudcostRelation.png' border='1px' />

More relevant guides and examples:
- [Port's Opencost integration](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost)
- [Port's AWS integration](https://docs.getport.io/build-your-software-catalog/sync-data-to-catalog/cloud-providers/aws/installations/installation)
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Tabs from "@theme/Tabs"
import TabItem from "@theme/TabItem"
import Prerequisites from "../templates/\_ocean_helm_prerequisites_block.mdx"
import AzurePremise from "../templates/\_ocean_azure_premise.mdx"
import DockerParameters from "./\_opencost-docker-parameters.mdx"
import AdvancedConfig from '../../../generalTemplates/_ocean_advanced_configuration_note.md'
import Prerequisites from "../../templates/\_ocean_helm_prerequisites_block.mdx"
import AzurePremise from "../../templates/\_ocean_azure_premise.mdx"
import DockerParameters from "../\_opencost-docker-parameters.mdx"
import AdvancedConfig from '../../../../generalTemplates/_ocean_advanced_configuration_note.md'
import PortApiRegionTip from "/docs/generalTemplates/_port_region_parameter_explanation_template.md"

# OpenCost
Expand Down
2 changes: 1 addition & 1 deletion docs/guides-and-tutorials/setup-slack-reminders.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Create a webhook in GitLab for triggering your GitLab:
- Construct the [pipeline trigger webhook URL](https://docs.gitlab.com/ee/ci/triggers/#use-a-webhook) with your project details.
- Back in Port, edit your action and in its `backend` step paste the **webhook URL** in the `Endpoint URL` field.

Now let's create the pipeline file that contains our logic. In your GitLab project create a new file named `gitlab-ci.yaml` and use the following snippet as its content:
Now let's create the pipeline file that contains our logic. In your GitLab project create a new file named `.gitlab-ci.yml` (note the period at the start of the filename) and use the following snippet as its content:

<details>
<summary><b>GitLab pipeline (click to expand)</b></summary>
Expand Down
6 changes: 5 additions & 1 deletion docs/integrations-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ This page contains a list of Port's available integrations, organized by the pla

## OpenCost

- [OpenCost integration](/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost.md)
- [OpenCost integration](/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost/opencost.md)

- [Connect Opencost resource with ArgoCD K8 resource](/build-your-software-catalog/sync-data-to-catalog/argocd/guides/connect-opencost-resource-with-argocd-k8s-resources.md)

- [Connect Opencost resource with AWS resource](/build-your-software-catalog/sync-data-to-catalog/cloud-cost/opencost/guides/connect-opencost-resource-with-aws-resource.md)

## Dynatrace

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.