Skip to content

[CI/CD] Add Target Allocator(TA) Build to Build and Upload Workflow #246

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-and-upload-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- main
- target-allocator
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/build-and-upload-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
# Use terraform assume role for uploading to ecr
AWS_ASSUME_ROLE: ${{ secrets.TERRAFORM_AWS_ASSUME_ROLE }}
ECR_OPERATOR_STAGING_REPO: ${{ vars.ECR_OPERATOR_STAGING_REPO }}
ECR_TARGET_ALLOCATOR_STAGING_REPO: ${{ vars.ECR_TARGET_ALLOCATOR_STAGING_REPO}}
ECR_OPERATOR_RELEASE_IMAGE: ${{ secrets.ECR_OPERATOR_RELEASE_IMAGE }}

on:
Expand Down Expand Up @@ -80,6 +81,15 @@ jobs:
push: true
tags: ${{ env.ECR_OPERATOR_STAGING_REPO }}:${{ inputs.tag }}
platforms: linux/amd64, linux/arm64
- name: Build Cloudwatch Agent Target Allocator Image and push to ECR
uses: docker/build-push-action@v4
if: steps.cached_binaries.outputs.cache-hit == false
with:
file: ./Dockerfile
context: ./amazon-cloudwatch-agent-target-allocator
push: true
tags: ${{ env.ECR_TARGET_ALLOCATOR_STAGING_REPO }}:${{ inputs.tag }}
platforms: linux/amd64, linux/arm64

e2e-test:
name: "Application Signals E2E Test"
Expand Down
3 changes: 3 additions & 0 deletions cmd/testing/basic-prometheus-sample-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
prometheus-sample-app
*.DS_Store
*.exe
25 changes: 25 additions & 0 deletions cmd/testing/basic-prometheus-sample-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:1.22-alpine

WORKDIR /app

# Set Go environment variables
ENV GOPROXY=direct
ENV GO111MODULE=on

# Install necessary packages
RUN apk add --no-cache git build-base

# Copy the go mod and sum files first to cache dependencies
COPY go.mod go.sum ./
RUN go mod download

# Copy the rest of the source code
COPY . .

# Build the application from the correct directory
RUN go build -o=/bin/main .

# Copy configuration file
COPY ./config.yaml /config.yaml

CMD ["/bin/main"]
1 change: 1 addition & 0 deletions cmd/testing/basic-prometheus-sample-app/ECR_REPO
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prom-test
134 changes: 134 additions & 0 deletions cmd/testing/basic-prometheus-sample-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# prometheus-sample-app

This Prometheus sample app generates all 4 Prometheus metric types (counter, gauge, histogram, summary) and exposes them at the `/metrics` endpoint

A health check endpoint also exists at `/`

The following is a list of optional command line flags for configuration:
* `listen_address`: (default = `0.0.0.0:8080`)this defines the address and port that the sample app is exposed to. This is primarily to conform with the test framework requirements.
* `metric_count`: (default=1) the amount of each type of metric to generate. The same amount of metrics is always generated per metric type.
* `label_count`: (default=1) the amount of labels per metric to generate.
* `datapoint_count`: (default=1) the number of data-points per metric to generate.

Steps for running locally:
```bash
$ go build .
$ ./prometheus-sample-app -listen_address=0.0.0.0:4567 -metric_count=100
```

Steps for running in docker:

```bash
$ docker build . -t prometheus-sample-app
$ docker run -it -p 8080:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080
$ curl localhost:8080/metrics
```

Note that the port in LISTEN_ADDRESS must match the the second port specified in the port-forward

More functioning examples:

```bash
$ docker build . -t prometheus-sample-app
$ docker run -it -p 9001:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080
$ curl localhost:9001/metrics
```

```bash
$ docker build . -t prometheus-sample-app
$ docker run -it -p 9001:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080 -metric_count=100
$ curl localhost:9001/metrics
```

Running the commands above will require a config file for setting defaults. The config file is provided in this application. To modify it just change the values.
To override config file defaults you can specify your arguments via command line

Usage of generate:

-is_random

Metrics specification

-metric_count int

Amount of metrics to create

-metric_frequency int

Refresh interval in seconds

-metric_type string

Type of metric (counter, gauge, histogram, summary)

-label_count int

Amount of labels to create per metric

-datapoint_count int

Number of datapoints to create per metric

Example:
```bash
$ docker build . -t prometheus-sample-app
$ docker run -it -p 8080:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080 generate -metric_type=summary -metric_count=30 -metric_frequency=10
$ curl localhost:8080/metrics
```
```bash
$ docker build . -t prometheus-sample-app
$ docker run -it -p 8080:8080 prometheus-sample-app /bin/main -listen_address=0.0.0.0:8080 generate -metric_type=all -is_random=true
$ curl localhost:8080/metrics
```

## Clustering:
Deploy the example deployment configuration of 5 instances of Prometheus-Sample-App along with configured OTEL Collector.

### Pre-requisites:
- Docker
- Docker Image Prometheus-Sample-App
- A Kubernetes cluster

### Deployment on Minikube:
- Run Docker
- Start Minikube
```bash
$ minikube start
```
- Run following command to deploy:
```bash
$ kubectl apply -f otel-collector-k8s-deployment.yaml
$ kubectl create clusterrolebinding service-reader-pod --clusterrole=service-reader --serviceaccount=default:default
$ kubectl apply -f prometheus-sample-app-k8s-deployment.yaml
```
- Run following command to monitor logs from OTEL Collector Logging exporter :
```bash
$ kubectl logs <otel-collector-pod-name>
```
### Deployment on EKS:
- Create your cluster on EKS
```bash
$ eksctl create cluster --name <cluster-name> --region <region> --with-oidc --ssh-access --ssh-public-key <public-key>
```
- Create repository on Amazon ECR to push docker image of Prometheus-Sample-App
- Push the prometheus_sample_app docker image to this repository
```bash
$ aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
$ docker build -t prometheus_sample_app .
$ docker tag prometheus_sample_app:latest aws_account_id.dkr.ecr.region.amazonaws.com/my-repository:tag
$ docker push aws_account_id.dkr.ecr.region.amazonaws.com/my-repository:tag
```
- Update imagePullPolicy of 'prometheus-sample-app-k8s-deployment.yaml' to IfNotPresent
- Copy image URI from the AWS ECR repository and update in 'prometheus-sample-app-k8s-deployment.yaml'
- Run following command to deploy:
```bash
$ kubectl apply -f otel-collector-k8s-deployment.yaml
$ kubectl create clusterrolebinding service-reader-pod --clusterrole=service-reader --serviceaccount=default:default
$ kubectl apply -f prometheus-sample-app-k8s-deployment.yaml
```
- Run following command to monitor logs from OTEL Collector Logging exporter :
```bash
$ kubectl logs <otel-collector-pod-name>
```

Currently, OTEL Collector is configured with Logging exporter. In this example, all replica Prometheus-Sample-App pods will produce identical metrics, and the Prometheus Exporter doesn't ingest identical metrics (same name and label) from different sources.
8 changes: 8 additions & 0 deletions cmd/testing/basic-prometheus-sample-app/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
Address: "0.0.0.0:8080"
Type: "all"
MetricsCount: 1
LabelsCount: 1
DataPointCount: 1
Frequency: 1
Random: false
16 changes: 16 additions & 0 deletions cmd/testing/basic-prometheus-sample-app/deploy-basic-prom-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
aws_account_id="956457624121"
repository="prom-sample-app"
region="us-west-2"

aws ecr get-login-password --region $region | docker login --username AWS --password-stdin $aws_account_id.dkr.ecr.$region.amazonaws.com

docker build --platform=linux/amd64 -t prometheus_sample_app .
docker tag prometheus_sample_app:latest $aws_account_id.dkr.ecr.$region.amazonaws.com/$repository:latest
docker push $aws_account_id.dkr.ecr.$region.amazonaws.com/$repository:latest


NEW_IMAGE=$aws_account_id.dkr.ecr.$region.amazonaws.com/$repository:latest
sed -i '' "s|\$IMAGE|$NEW_IMAGE|g" prometheus-sample-app-k8s-deployment.yaml

kubectl apply -f prometheus-sample-app-k8s-deployment.yaml

20 changes: 20 additions & 0 deletions cmd/testing/basic-prometheus-sample-app/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/open-o11y/prometheus-sample-app

go 1.22

require (
github.com/prometheus/client_golang v1.18.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
golang.org/x/sys v0.15.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
38 changes: 38 additions & 0 deletions cmd/testing/basic-prometheus-sample-app/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM=
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
11 changes: 11 additions & 0 deletions cmd/testing/basic-prometheus-sample-app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"github.com/open-o11y/prometheus-sample-app/metrics"
)

func main() {

cmd := metrics.CommandLine{}
cmd.Run()
}
Loading
Loading