Skip to content

Commit

Permalink
Osm simple metrics container (#291)
Browse files Browse the repository at this point in the history
* Add osm-simple-metrics container

* Add chartpress section for osm-simple-metrics and helm template

* Set fixed port for DB in osm-metrics

* Fix mapping values - context, job metrics

* Fix path for aws bucket name

* Get metrics code from main branch
  • Loading branch information
Ruben L. Mendoza authored May 16, 2023
1 parent d516466 commit 51a2eed
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 1 deletion.
4 changes: 3 additions & 1 deletion chartpress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ charts:
overpass-api:
valuesPath: overpassApi.image
taginfo:
valuesPath: taginfo.image
valuesPath: taginfo.image
osm-simple-metrics:
valuesPath: osmSimpleMetrics.image
10 changes: 10 additions & 0 deletions compose/osm-simple-metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'
services:
osm-simple-metrics:
image: osm-simple-metrics:v1
build:
context: ../images/osm-simple-metrics
dockerfile: Dockerfile
env_file:
- ../envs/.env.db
- ../envs/.env.cloudprovider
11 changes: 11 additions & 0 deletions images/osm-simple-metrics/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:18

# Create app directory
WORKDIR /usr/src/app

# Clone
RUN git clone https://github.com/developmentseed/osm-simple-metrics.git ./

RUN npm install && npm link
COPY start.sh /
CMD /start.sh
18 changes: 18 additions & 0 deletions images/osm-simple-metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# OSM Simple Metrics

This is a container that allows to extract simple metrics calculations for an OSM database.

Repo: https://github.com/developmentseed/osm-simple-metrics

#### Building the container


```sh
docker compose -f compose/osm-simple-metrics.yml build
```

#### Access the container

```sh
docker-compose -f compose/osm-simple-metrics.yml run osm-simple-metrics bash
```
14 changes: 14 additions & 0 deletions images/osm-simple-metrics/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
conString=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}
bucket_name="${AWS_S3_BUCKET#s3://}"

CLIS=(cumulative_elements current_elements changeset_counts)
for cli in "${CLIS[@]}"; do
echo "Star running... $cli"
if [ $CLOUDPROVIDER == "aws" ]; then
osm-simple-metrics $cli \
$conString \
-csv \
-s3 $bucket_name
fi
done
68 changes: 68 additions & 0 deletions osm-seed/templates/jobs/osm-simple-metrics-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{- if .Values.osmSimpleMetrics.enabled -}}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ .Release.Name }}-osm-simple-metrics-job
labels:
app: {{ template "osm-seed.name" . }}
component: osm-simple-metrics-job
environment: {{ .Values.environment }}
release: {{ .Release.Name }}
spec:
schedule: {{ quote .Values.osmSimpleMetrics.schedule }}
startingDeadlineSeconds: 100
successfulJobsHistoryLimit: 2
failedJobsHistoryLimit: 2
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
spec:
containers:
- name: {{ .Release.Name }}-osm-simple-metrics-job
image: {{ .Values.osmSimpleMetrics.image.name }}:{{ .Values.osmSimpleMetrics.image.tag }}
{{- if .Values.osmSimpleMetrics.resources.enabled }}
resources:
requests:
memory: {{ .Values.osmSimpleMetrics.resources.requests.memory }}
cpu: {{ .Values.osmSimpleMetrics.resources.requests.cpu }}
limits:
memory: {{ .Values.osmSimpleMetrics.resources.limits.memory }}
cpu: {{ .Values.osmSimpleMetrics.resources.limits.cpu }}
{{- end }}
env:
- name: POSTGRES_HOST
value: {{ .Release.Name }}-db
- name: POSTGRES_DB
value: {{ .Values.db.env.POSTGRES_DB }}
- name: POSTGRES_PASSWORD
value: {{ quote .Values.db.env.POSTGRES_PASSWORD }}
- name: POSTGRES_USER
value: {{ .Values.db.env.POSTGRES_USER }}
- name: CLOUDPROVIDER
value: {{ .Values.cloudProvider }}
# In case cloudProvider=aws
{{- if eq .Values.cloudProvider "aws" }}
- name: AWS_S3_BUCKET
value: {{ .Values.AWS_S3_BUCKET }}
{{- end }}
# In case cloudProvider=gcp
{{- if eq .Values.cloudProvider "gcp" }}
- name: GCP_STORAGE_BUCKET
value: {{ .Values.GCP_STORAGE_BUCKET }}
{{- end }}
# In case cloudProvider=azure
{{- if eq .Values.cloudProvider "azure" }}
- name: AZURE_STORAGE_ACCOUNT
value: {{ .Values.AZURE_STORAGE_ACCOUNT }}
- name: AZURE_CONTAINER_NAME
value: {{ .Values.AZURE_CONTAINER_NAME }}
- name: AZURE_STORAGE_CONNECTION_STRING
value: {{ .Values.AZURE_STORAGE_CONNECTION_STRING }}
{{- end }}
restartPolicy: OnFailure
{{- if .Values.osmSimpleMetrics.nodeSelector.enabled }}
nodeSelector:
{{ .Values.osmSimpleMetrics.nodeSelector.label_key }}: {{ .Values.osmSimpleMetrics.nodeSelector.label_value }}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions osm-seed/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -646,3 +646,22 @@ taginfo:
cpu: '2'
nodeSelector:
enabled: false
# ====================================================================================================
# Variables for osm-simple-metrics
# ====================================================================================================
osmSimpleMetrics:
enabled: false
image:
name: ''
tag: ''
schedule: '* */1 * * *'
resources:
enabled: false
requests:
memory: '1Gi'
cpu: '2'
limits:
memory: '2Gi'
cpu: '2'
nodeSelector:
enabled: false

0 comments on commit 51a2eed

Please sign in to comment.