Add cron job for Gnocchi to purge deleted resources

The current gnocchi chart doesn't purge the resources/metrics for
the deleted openstack resources. This commit adds a cron job to
periodically purge the deleted resources data from gnocchi database.
By default, cron job runs daily and purges the deleted resources with
its associcated metrics which have lived more that 1 day.

Change-Id: Id45b92b91bb7668b35c3b5a7379283de51a1256a
Story: 2005016
Task: 29494
Signed-off-by: Angie Wang <angie.wang@windriver.com>
This commit is contained in:
Angie Wang 2019-02-19 17:51:43 -05:00 committed by Chris Wedgwood
parent 7578ba5a4b
commit a5aeab344b
4 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,22 @@
{{/*
Copyright 2019 The Openstack-Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}
set -ex
echo "Purging the deleted resources with its associated metrics which have lived more than ${DELETED_RESOURCES_TTL}"
gnocchi resource batch delete "ended_at < '-${DELETED_RESOURCES_TTL}'"
exit 0

View File

@ -46,6 +46,8 @@ data:
{{ tuple "bin/_gnocchi-metricd.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
gnocchi-statsd.sh: |
{{ tuple "bin/_gnocchi-statsd.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
gnocchi-resources-cleaner.sh: |
{{ tuple "bin/_gnocchi-resources-cleaner.sh.tpl" . | include "helm-toolkit.utils.template" | indent 4 }}
ks-service.sh: |
{{- include "helm-toolkit.scripts.keystone_service" . | indent 4 }}
ks-endpoints.sh: |

View File

@ -0,0 +1,96 @@
{{/*
Copyright 2019 The Openstack-Helm Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/}}
{{- if .Values.manifests.cron_job_resources_cleaner }}
{{- $envAll := . }}
{{- $mounts_gnocchi_resources_cleaner := .Values.pod.mounts.gnocchi_resources_cleaner.gnocchi_resources_cleaner }}
{{- $mounts_gnocchi_resources_cleaner_init := .Values.pod.mounts.gnocchi_resources_cleaner.init_container }}
{{- $serviceAccountName := "gnocchi-resources-cleaner" }}
{{ tuple $envAll "resources_cleaner" $serviceAccountName | include "helm-toolkit.snippets.kubernetes_pod_rbac_serviceaccount" }}
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: gnocchi-resources-cleaner
annotations:
{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
spec:
schedule: {{ .Values.jobs.resources_cleaner.cron | quote }}
successfulJobsHistoryLimit: {{ .Values.jobs.resources_cleaner.history.success }}
failedJobsHistoryLimit: {{ .Values.jobs.resources_cleaner.history.failed }}
concurrencyPolicy: Forbid
jobTemplate:
metadata:
labels:
{{ tuple $envAll "gnocchi" "resources-cleaner" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }}
spec:
template:
spec:
serviceAccountName: {{ $serviceAccountName }}
restartPolicy: OnFailure
nodeSelector:
{{ .Values.labels.job.node_selector_key }}: {{ .Values.labels.job.node_selector_value }}
initContainers:
{{ tuple $envAll "resources_cleaner" $mounts_gnocchi_resources_cleaner_init | include "helm-toolkit.snippets.kubernetes_entrypoint_init_container" | indent 12 }}
containers:
- name: gnocchi-resources-cleaner
{{ tuple $envAll "gnocchi_resources_cleaner" | include "helm-toolkit.snippets.image" | indent 14 }}
{{ tuple $envAll $envAll.Values.pod.resources.jobs.resources_cleaner | include "helm-toolkit.snippets.kubernetes_resources" | indent 14 }}
env:
{{- with $env := dict "ksUserSecret" .Values.secrets.identity.admin }}
{{- include "helm-toolkit.snippets.keystone_openrc_env_vars" $env | indent 16 }}
{{- end }}
- name: OS_AUTH_TYPE
valueFrom:
secretKeyRef:
name: {{ $.Values.secrets.identity.admin }}
key: OS_AUTH_TYPE
- name: OS_TENANT_NAME
valueFrom:
secretKeyRef:
name: {{ $.Values.secrets.identity.admin }}
key: OS_TENANT_NAME
- name: DELETED_RESOURCES_TTL
value: {{ .Values.jobs.resources_cleaner.deleted_resources_ttl | quote }}
command:
- /tmp/gnocchi-resources-cleaner.sh
volumeMounts:
- name: gnocchi-bin
mountPath: /tmp/gnocchi-resources-cleaner.sh
subPath: gnocchi-resources-cleaner.sh
readOnly: true
- name: pod-etc-gnocchi
mountPath: /etc/gnocchi
- name: gnocchi-etc
mountPath: /etc/gnocchi/gnocchi.conf
subPath: gnocchi.conf
readOnly: true
{{ if $mounts_gnocchi_resources_cleaner.volumeMounts }}{{ toYaml $mounts_gnocchi_resources_cleaner.volumeMounts | indent 14 }}{{ end }}
volumes:
- name: pod-etc-gnocchi
emptyDir: {}
- name: gnocchi-etc
secret:
secretName: gnocchi-etc
defaultMode: 0444
- name: gnocchi-bin
configMap:
name: gnocchi-bin
defaultMode: 0555
{{ if $mounts_gnocchi_resources_cleaner.volumes }}{{ toYaml $mounts_gnocchi_resources_cleaner.volumes | indent 10 }}{{ end }}
{{- end }}

View File

@ -58,6 +58,15 @@ images:
- dep_check
- image_repo_sync
jobs:
resources_cleaner:
# daily
cron: "0 */24 * * *"
deleted_resources_ttl: '1day'
history:
success: 3
failed: 1
network:
api:
ingress:
@ -155,6 +164,19 @@ dependencies:
service: oslo_db_postgresql
- endpoint: internal
service: metric
resources_cleaner:
jobs:
- gnocchi-storage-init
- gnocchi-db-sync
- gnocchi-ks-user
- gnocchi-ks-endpoints
services:
- endpoint: internal
service: oslo_db
- endpoint: internal
service: identity
- endpoint: internal
service: metric
storage_init:
services: null
tests:
@ -193,6 +215,9 @@ pod:
gnocchi_metricd:
init_container: null
gnocchi_metricd:
gnocchi_resources_cleaner:
init_container: null
gnocchi_resources_cleaner:
gnocchi_tests:
init_container: null
gnocchi_tests:
@ -288,6 +313,13 @@ pod:
limits:
memory: "1024Mi"
cpu: "2000m"
resources_cleaner:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "1024Mi"
cpu: "2000m"
tests:
requests:
memory: "124Mi"
@ -577,6 +609,7 @@ endpoints:
manifests:
configmap_bin: true
configmap_etc: true
cron_job_resources_cleaner: true
daemonset_metricd: true
daemonset_statsd: true
deployment_api: true