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

OPS-6220-Ionos-Exporter Extension #4

Open
wants to merge 56 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
75cbc31
implementation for s3 metrics and ipmetrics
aebyss May 2, 2024
3043a1e
initial push
aebyss May 2, 2024
367c7d4
fixed problems with crashing while using go routine
aebyss May 2, 2024
672a5d7
x
aebyss May 2, 2024
b07829e
Wait groups work in progress
aebyss May 6, 2024
f3568dd
implemented concurrency for s3 log parsing, fixed bugs, implemented a…
aebyss May 23, 2024
3a3e559
fixing github action
aebyss May 23, 2024
2c23564
moved GetHeadBucket from local file to helper.go
aebyss May 23, 2024
2222a26
fixed declared and not used error
aebyss May 23, 2024
cf7f08b
added go mod tidy for installing dependencies
aebyss May 23, 2024
1bc7e18
removed some of log Statements and added secret management for s3
aebyss May 23, 2024
b1b2614
resotred CollectResources func in main
aebyss May 24, 2024
f7abecc
reverted api cycle to 900
aebyss May 24, 2024
73d98ac
removed logging to a file
aebyss May 24, 2024
8ea6e5d
added new labels removed some comments
aebyss May 28, 2024
3511721
Fix typo
simoncolincap May 29, 2024
0850549
fixed scraping inconsistencies of metrics and added error handling fo…
aebyss May 31, 2024
b3e2be1
Merge branch 'DBP-ionos-exporter-expansion' of https://github.com/dBi…
aebyss May 31, 2024
3b43466
added scraping of bucket tags and pushing them to prometheus
aebyss Jun 13, 2024
eb30380
added git.sum file
aebyss Jun 13, 2024
c09f3af
removed customcollector.go
aebyss Jun 13, 2024
283b5a1
added error handling for number of IPs
aebyss Jun 21, 2024
8a1f92d
Added logger instead of print and changed number of ips from GaugeVec…
aebyss Jun 24, 2024
007e640
Added postgress cluster metrics and telemetry metrics
aebyss Jul 2, 2024
298524d
refactoring prometheus.go@
aebyss Jul 3, 2024
f063b1f
Bug for when bucket doesnt have tags wont be pushed to prometheus fixed
aebyss Jul 4, 2024
663ba85
Added Config.yaml
aebyss Jul 4, 2024
675ba61
temp removal of postgress collection before i configure the deploymen…
aebyss Jul 4, 2024
a2f7255
s3 refactor and ConfigMap definition
aebyss Jul 5, 2024
f184409
fixed configmap locatioN
aebyss Jul 5, 2024
064855c
fixed syntax for helm deployment
aebyss Jul 5, 2024
6ef9510
removed print statements used for debugging
aebyss Jul 5, 2024
dde6c49
syntax fixes and added comments to the ionos_scrapper functions
aebyss Jul 9, 2024
38039d1
fixed config path loader
aebyss Jul 15, 2024
ede28cd
added documentation and removed redundant code
aebyss Aug 1, 2024
9a79289
removed local loading of .env
aebyss Aug 2, 2024
289725d
removed .env in postgres_scraper
aebyss Aug 2, 2024
defffda
debugging s3 function not loading in pods
aebyss Aug 2, 2024
41e0088
ommited usage of config.yaml for s3 scraping
aebyss Aug 2, 2024
078fa1f
syntax fixes, some commets removed
aebyss Aug 5, 2024
4e075c4
added buffer to reading lines
aebyss Aug 6, 2024
3bdbead
added config changes and added env template file for running localy
aebyss Aug 9, 2024
fbd3252
added path to config in deploymenet yaml
aebyss Aug 9, 2024
f52ed80
added default path to config.yaml
aebyss Aug 9, 2024
9bf9330
removed default path to config and removed os.Exit when n oconfig set
aebyss Aug 9, 2024
5ec471d
trying gracefully skipping local setting of config yaml
aebyss Aug 9, 2024
ab7cdda
syntax fix
aebyss Aug 9, 2024
303846b
fixed nil dereference problem
aebyss Aug 9, 2024
cdef725
added default path again
aebyss Aug 9, 2024
f39fa28
removed line configfile as enviroment variable only as parameter is n…
aebyss Aug 14, 2024
f256591
Removed cost-calc sequenqce diagramm from Documentation
aebyss Aug 14, 2024
f9e9fab
make s3 part optional
JannikBadenhop Oct 10, 2024
7f03d99
Fix if, Name -> Owner
JannikBadenhop Oct 10, 2024
d9986d3
increase minor version and reset patch version, since values and defa…
JannikBadenhop Oct 10, 2024
b06d005
revert version changes
JannikBadenhop Oct 10, 2024
7c6aeba
fix quoting and whitespace issues
JannikBadenhop Oct 11, 2024
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
5 changes: 5 additions & 0 deletions .github/workflows/build-and-push-to-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ on:

jobs:
build_image_on_push:
permissions:
packages: write
security-events: write
actions: read
contents: read
uses: ./.github/workflows/imagetoghcr-on-push.yaml
with:
image_name: "ionos-exporter"
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ COPY go.sum .

RUN go mod download

RUN go mod tidy

FROM build_deps AS build

COPY . .
Expand Down
184 changes: 184 additions & 0 deletions Documentation/arch_diagramm_io_exp.xml

Large diffs are not rendered by default.

380 changes: 380 additions & 0 deletions Documentation/ionos_exporter_sequenzdiagram_postgres.drawio

Large diffs are not rendered by default.

423 changes: 423 additions & 0 deletions Documentation/ionos_exporter_sequenzdiagram_s3.drawio

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions charts/ionos-exporter/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
metrics:
- name: ionos_dbaas_postgres_transactions:rate2m
description: Per-second average rate of SQL transactions (that have been committed), calculated over the last 2 minutes.
type: gauge
- name: ionos_dbaas_postgres_connections_count
description: Number of connections per instance and state. active, disabled, fastpath function call, idle, idle in transaction, idle in transaction (aborted).
type: gauge
- name: ionos_dbaas_postgres_cpu_rate5m
description: The average CPU utilization over the past 5 minutes.
type: gauge
- name: ionos_dbaas_postgres_disk_io_time_weighted_seconds_rate5m
description: The rate of disk I/O time, in seconds, over a five-minute period. Provides insight into performance of a disk, as high values may indicate that the disk is being overused or is experiencing performance issues.
type: gauge
- name: ionos_dbaas_postgres_instance_count
description: Desired number of instances. The number of currently ready and running instances may be different. ionos_dbaas_postgres_role provides information about running instances split by role.
type: gauge
- name: ionos_dbaas_postgres_load5
description: Linux load average for the last 5 minutes. This metric is represented as a number between 0 and 1 (can be greater than 1 on multicore machines), where 0 indicates that the CPU core is idle and 1 indicates that the CPU core is fully utilized. Higher values may indicate that the system is experiencing performance issues or is approaching capacity.
type: gauge
- name: ionos_dbaas_postgres_memory_available_bytes
description: Available memory in bytes.
type: gauge
- name: ionos_dbaas_postgres_memory_total_bytes
description: Total memory of the underlying machine in bytes. Some of it is used for our management and monitoring tools and not available to PostgreSQL. During horizontal scaling you might see different values for each instance.
type: gauge
- name: ionos_dbaas_postgres_role
description: Current role of the instance. Provides whether an instance is currently "master" or "replica".
type: gauge
- name: ionos_dbaas_postgres_storage_available_bytes
description: Free available disk space per instance in bytes.
type: gauge
- name: ionos_dbaas_postgres_storage_total_bytes
description: Total disk space per instance in bytes. During horizontal scaling you might see different values for each instance.
type: gauge
- name: ionos_dbaas_postgres_user_tables_idx_scan
description: Number of index scans per table/schema.
type: gauge
7 changes: 7 additions & 0 deletions charts/ionos-exporter/templates/ConfigMap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: ionos-exporter-config
data:
config.yaml: |-
{{ .Files.Get "config.yaml" | nindent 4 }}
33 changes: 29 additions & 4 deletions charts/ionos-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ spec:
- name: metrics
containerPort: {{ .Values.containerPort }}
protocol: TCP
args:
- "-config=/etc/ionos-exporter/config.yaml"
livenessProbe:
httpGet:
path: /metrics
Expand All @@ -46,20 +48,43 @@ spec:
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
{{- if .Values.ionos.s3.enabled }}
- name: AWS_ACCESS_KEY_ID
JannikBadenhop marked this conversation as resolved.
Show resolved Hide resolved
valueFrom:
secretKeyRef:
name: {{ .Values.ionos.credentials.secret_name }}
key: {{ .Values.ionos.s3.credentials.access_key }}
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{ .Values.ionos.credentials.secret_name }}
key: {{ .Values.ionos.s3.credentials.secret_key }}
{{- end }}
- name: IONOS_USERNAME
valueFrom:
secretKeyRef:
name: {{ .Values.ionos_credentials_secret_name }}
key: {{ .Values.ionos_credentials_username_key }}
name: {{ .Values.ionos.credentials.secret_name }}
key: {{ .Values.ionos.credentials.username_key }}
- name: IONOS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.ionos_credentials_secret_name }}
key: {{ .Values.ionos_credentials_password_key }}
name: {{ .Values.ionos.credentials.secret_name }}
key: {{ .Values.ionos.credentials.password_key }}
- name: IONOS_EXPORTER_S3_ENABLED
value: {{ .Values.ionos.s3.enabled | quote }}
- name: IONOS_EXPORTER_APPLICATION_CONTAINER_PORT
value: {{ .Values.containerPort | quote }}
- name: IONOS_EXPORTER_API_CYCLE
value: {{ .Values.ionosApiCycle | quote }}
volumeMounts:
- name: config-volume
readOnly: true
mountPath: /etc/ionos-exporter/config.yaml
subPath: config.yaml
volumes:
- name: config-volume
configMap:
name: ionos-exporter-config
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
15 changes: 12 additions & 3 deletions charts/ionos-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ image:
imagePullSecrets: []

# credentials
ionos_credentials_secret_name: "ionos-exporter-credentials"
ionos_credentials_username_key: "username"
ionos_credentials_password_key: "password"
# ionos_credentials_secret_token: "ionos-exporter-token"
# ionos_credentials_token_key: "token"
ionos:
credentials:
secret_name: "ionos-exporter-credentials"
username_key: "username"
password_key: "password"
s3:
enabled: false
credentials:
secret_key: "secretKey"
access_key: "accessKey"

service:
type: ClusterIP
Expand Down
1 change: 1 addition & 0 deletions env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IONOS_TOKEN=""
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ module ionos-exporter
go 1.20

require (
github.com/aws/aws-sdk-go v1.52.0
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.2
github.com/ionos-cloud/sdk-go/v6 v6.1.9
github.com/joho/godotenv v1.5.1
github.com/prometheus/client_golang v1.16.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
golang.org/x/net v0.15.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/sys v0.21.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)
34 changes: 30 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
github.com/aws/aws-sdk-go v1.52.0 h1:ptgek/4B2v/ljsjYSEvLQ8LTD+SQyrqhOOWvHc/VGPI=
github.com/aws/aws-sdk-go v1.52.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
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.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand All @@ -11,10 +15,23 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
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/ionos-cloud/sdk-go-dbaas-postgres v1.1.2 h1:AaKbci+kVS6/k43VwJwmXxCJ7pzj9jwuOPqO8Wd5560=
github.com/ionos-cloud/sdk-go-dbaas-postgres v1.1.2/go.mod h1:nmJEwuRX65A5/PxwvdFW0XrV+N6WFYnMV1TiIafAwz4=
github.com/ionos-cloud/sdk-go/v6 v6.1.9 h1:Iq3VIXzeEbc8EbButuACgfLMiY5TPVWUPNrF+Vsddo4=
github.com/ionos-cloud/sdk-go/v6 v6.1.9/go.mod h1:EzEgRIDxBELvfoa/uBN0kOQaqovLjUWEB7iW4/Q+t4k=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
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 v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
Expand All @@ -23,18 +40,22 @@ github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
github.com/prometheus/procfs v0.10.1 h1:kYK1Va/YMlutzCGazswoHKo//tZVlFpKYh+PymziUAg=
github.com/prometheus/procfs v0.10.1/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8=
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/oauth2 v0.6.0 h1:Lh8GPgSKBfWSwFvtuWOfeI3aAAnbXTSutYxJiOJFgIw=
golang.org/x/oauth2 v0.6.0/go.mod h1:ycmewcwgD4Rpr3eZJLSB4Kyyljb3qDh40vJ8STE5HKw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
Expand All @@ -43,3 +64,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.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/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
49 changes: 49 additions & 0 deletions internal/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@ package internal

import (
"fmt"
"io/ioutil"
"log"
"os"

aws "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
"gopkg.in/yaml.v2"
)

type Config struct {
Metrics []MetricConfig `yaml:"metrics"`
}

type MetricConfig struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Type string `yaml:"type"`
}

func GetEnv(key string, fallback string) string {
value, ok := os.LookupEnv(key)
if !ok {
Expand All @@ -20,3 +37,35 @@ func GetEnv(key string, fallback string) string {
}
}
}

func GetHeadBucket(client *s3.S3, bucketName string) error {
input := &s3.HeadBucketInput{
Bucket: aws.String(bucketName),
}
_, err := client.HeadBucket(input)
if err != nil {
if reqErr, ok := err.(awserr.RequestFailure); ok && reqErr.StatusCode() == 403 {
log.Printf("Skipping bucket %s due to Forbidden error: %v\n", bucketName, err)
return err
}
log.Printf("Problem getting the location for bucket %s: %v\n", bucketName, err)
return err
}
log.Printf("Bucket %s exists and is accessible\n", bucketName)
return nil
}

func LoadConfig(filename string) (*Config, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}

var config Config
err = yaml.Unmarshal(data, &config)
if err != nil {
return nil, err
}

return &config, nil
}
Loading
Loading