Adding Prometheus charm 83/10183/2
authorsousaedu <eduardo.sousa@canonical.com>
Fri, 15 Jan 2021 16:59:14 +0000 (16:59 +0000)
committersousaedu <eduardo.sousa@canonical.com>
Fri, 15 Jan 2021 17:03:49 +0000 (17:03 +0000)
Change-Id: Ib17db114e32c2cbaaa89474e92890263f705e0e5
Signed-off-by: sousaedu <eduardo.sousa@canonical.com>
15 files changed:
installers/charm/prometheus-k8s/.gitignore [new file with mode: 0644]
installers/charm/prometheus-k8s/.yamllint.yaml [new file with mode: 0644]
installers/charm/prometheus-k8s/README.md [new file with mode: 0755]
installers/charm/prometheus-k8s/config.yaml [new file with mode: 0755]
installers/charm/prometheus-k8s/icon.svg [new file with mode: 0644]
installers/charm/prometheus-k8s/layer.yaml [new file with mode: 0644]
installers/charm/prometheus-k8s/metadata.yaml [new file with mode: 0755]
installers/charm/prometheus-k8s/reactive/prometheus.py [new file with mode: 0644]
installers/charm/prometheus-k8s/reactive/spec_template.yaml [new file with mode: 0644]
installers/charm/prometheus-k8s/test-requirements.txt [new file with mode: 0644]
installers/charm/prometheus-k8s/tests/basic_deployment.py [new file with mode: 0644]
installers/charm/prometheus-k8s/tests/bundles/prometheus-ha.yaml [new file with mode: 0644]
installers/charm/prometheus-k8s/tests/bundles/prometheus.yaml [new file with mode: 0644]
installers/charm/prometheus-k8s/tests/tests.yaml [new file with mode: 0644]
installers/charm/prometheus-k8s/tox.ini [new file with mode: 0644]

diff --git a/installers/charm/prometheus-k8s/.gitignore b/installers/charm/prometheus-k8s/.gitignore
new file mode 100644 (file)
index 0000000..712eb96
--- /dev/null
@@ -0,0 +1,24 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+release/
+__pycache__
+.tox
diff --git a/installers/charm/prometheus-k8s/.yamllint.yaml b/installers/charm/prometheus-k8s/.yamllint.yaml
new file mode 100644 (file)
index 0000000..21b95b5
--- /dev/null
@@ -0,0 +1,34 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+---
+
+extends: default
+rules:
+  line-length: disable
+yaml-files:
+  - '*.yaml'
+  - '*.yml'
+  - '.yamllint'
+ignore: |
+ reactive/
+ .tox
+ release/
diff --git a/installers/charm/prometheus-k8s/README.md b/installers/charm/prometheus-k8s/README.md
new file mode 100755 (executable)
index 0000000..e6ae801
--- /dev/null
@@ -0,0 +1,108 @@
+<!-- Copyright 2021 Canonical Ltd.
+
+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.
+
+For those usages not covered by the Apache License, Version 2.0 please
+contact: legal@canonical.com
+
+To get in touch with the maintainers, please contact:
+osm-charmers@lists.launchpad.net -->
+
+# Overview
+
+Prometheus for Juju CAAS
+
+## Testing
+
+The tests of this charm are done using tox and Zaza.
+
+
+
+### Prepare environment
+
+The machine in which the tests are run needs access to a juju k8s controller. The easiest way to approach this is by executing the following commands:
+
+```
+sudo apt install tox -y
+sudo snap install microk8s --classic
+sudo snap install juju
+
+microk8s.status --wait-ready
+microk8s.enable storage dashboard dns
+
+juju bootstrap microk8s k8s-cloud
+```
+
+If /usr/bin/python does not exist, you should probably need to do this:
+
+```
+sudo ln -s /usr/bin/python3 /usr/bin/python
+```
+### Build Charm
+
+**Download dependencies:**
+
+```
+mkdir -p ~/charm/layers ~/charm/build ~/charm/interfaces
+git clone https://git.launchpad.net/canonical-osm ~/canonical-osm
+
+cd ~/charm/layers
+git clone https://git.launchpad.net/charm-k8s-prometheus prometheus-k8s 
+
+cd ~/charm/interfaces
+mv ~/canonical-osm/charms/interfaces/* .
+```
+
+**Charm structure:**
+
+```
+├── config.yaml
+├── icon.svg
+├── layer.yaml
+├── metadata.yaml
+├── reactive
+│   ├── spec_template.yaml
+│   └── prometheus.py
+├── README.md
+├── test-requirements.txt
+├── tests
+│   ├── basic_deployment.py
+│   ├── bundles
+│   │   ├── prometheus-ha.yaml
+│   │   └── prometheus.yaml
+│   └── tests.yaml
+└── tox.ini
+```
+
+**Setup environment variables:**
+
+```
+export CHARM_LAYERS_DIR=~/charm/layers
+export CHARM_BUILD_DIR=~/charm/build
+export CHARM_INTERFACES_DIR=~/charm/interfaces
+```
+
+**Build:**
+
+```
+mkdir ~/charm/layers/prometheus-k8s/tests/build
+charm build ~/charm/layers/prometheus-k8s
+mv ~/charm/build/* ~/charm/layers/prometheus-k8s/tests/build/
+```
+
+### Test charm with Tox
+
+```
+cd ~/charm/layers/prometheus-k8s
+tox -e func
+```
diff --git a/installers/charm/prometheus-k8s/config.yaml b/installers/charm/prometheus-k8s/config.yaml
new file mode 100755 (executable)
index 0000000..3c3e9c6
--- /dev/null
@@ -0,0 +1,46 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+options:
+    advertised-hostname:
+        description: Advertised hostname
+        type: string
+        default: "prometheus"
+    advertised-port:
+        description: Prometheus Port
+        type: int
+        default: 9090
+    web-subpath:
+        description: Subpath for accessing Prometheus
+        type: string
+        default: /
+    default-target:
+        description: Default target to be added in Prometheus
+        type: string
+        default: ""
+    prometheus-image:
+        type: string
+        description: OCI image
+        default: rocks.canonical.com:443/prom/prometheus:latest
+    alpine-image:
+        type: string
+        description: OCI image
+        default: rocks.canonical.com:443/alpine:latest
diff --git a/installers/charm/prometheus-k8s/icon.svg b/installers/charm/prometheus-k8s/icon.svg
new file mode 100644 (file)
index 0000000..ffa6296
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="100px" height="100px" viewBox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <!-- Generator: Sketch 45.2 (43514) - http://www.bohemiancoding.com/sketch -->
+    <title>prometheus</title>
+    <desc>Created with Sketch.</desc>
+    <defs></defs>
+    <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <g id="prometheus" fill-rule="nonzero" fill="#B8B8B8">
+            <path d="M50.0004412,3.12178676e-15 C22.3871247,3.12178676e-15 0,22.3848726 0,49.9995588 C0,77.6133626 22.3871247,100 50.0004412,100 C77.6137577,100 100,77.6133626 100,49.9995588 C100,22.3848726 77.6128753,-1.77635684e-15 50.0004412,3.12178676e-15 Z M49.8864141,88.223871 C42.8334797,88.223871 37.1152482,83.6412396 37.1152482,77.9899953 L62.6575799,77.9899953 C62.6575799,83.6404692 56.9393484,88.223871 49.8864141,88.223871 Z M70.9802642,74.6007896 L28.7901876,74.6007896 L28.7901876,67.159792 L70.9810563,67.159792 L70.9810563,74.6007896 L70.9802642,74.6007896 Z M70.8289715,63.3298895 L28.9105881,63.3298895 C28.771177,63.1734883 28.6285974,63.0193985 28.493939,62.860686 C24.1753633,57.7603128 23.1582959,55.0976406 22.1705366,52.3841188 C22.1539023,52.2947467 27.4071661,53.4280774 31.1324525,54.2432125 C31.1324525,54.2432125 33.0493552,54.6746641 35.8518351,55.1716037 C33.1610425,52.1036753 31.5633596,48.2036619 31.5633596,44.2173581 C31.5633596,35.4658266 38.4642091,27.8183486 35.974612,21.6370353 C38.397672,21.8288772 40.9894511,26.6110549 41.164507,34.0882636 C43.740444,30.6258652 44.8185037,24.3027893 44.8185037,20.4258893 C44.8185037,16.4118494 47.5378123,11.7490913 50.257913,11.5896084 C47.8332688,15.4765242 50.886055,18.8087166 53.5998189,27.0748652 C54.6176783,30.1797752 54.4877725,35.4049611 55.2735442,38.7186628 C55.5341479,31.8362408 56.7508266,21.794207 61.2397056,18.3271859 C59.2594343,22.6933211 61.5327858,28.1565758 63.0876948,30.7830368 C65.5963025,35.020507 67.1171509,38.2309685 67.1171509,44.302878 C67.1171509,48.3739312 65.5717472,52.2069155 62.964918,55.2031922 C65.9289881,54.6623369 67.9757966,54.1746426 67.9757966,54.1746426 L77.6014994,52.3479077 C77.6022915,52.3471373 76.2034279,57.9421388 70.8289715,63.3298895 Z" id="path3023"></path>
+        </g>
+    </g>
+</svg>
\ No newline at end of file
diff --git a/installers/charm/prometheus-k8s/layer.yaml b/installers/charm/prometheus-k8s/layer.yaml
new file mode 100644 (file)
index 0000000..b58fad5
--- /dev/null
@@ -0,0 +1,28 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+includes:
+  - "layer:caas-base"
+  - 'layer:status'
+  - 'layer:leadership'
+  - 'interface:prometheus'
+
+repo: https://code.launchpad.net/osm-k8s-bundle
diff --git a/installers/charm/prometheus-k8s/metadata.yaml b/installers/charm/prometheus-k8s/metadata.yaml
new file mode 100755 (executable)
index 0000000..78aa778
--- /dev/null
@@ -0,0 +1,41 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+name: "prometheus-k8s"
+summary: "Prometheus Charm"
+maintainers:
+    - "SolutionsQA <solutionsqa@lists.canonical.com>"
+description: |
+  A CAAS charm to deploy Prometheus.
+tags:
+    - "application"
+series:
+    - "kubernetes"
+provides:
+    prometheus:
+        interface: prometheus
+storage:
+    database:
+        type: filesystem
+        location: /prometheus
+deployment:
+    type: stateful
+    service: cluster
diff --git a/installers/charm/prometheus-k8s/reactive/prometheus.py b/installers/charm/prometheus-k8s/reactive/prometheus.py
new file mode 100644 (file)
index 0000000..9aa4f26
--- /dev/null
@@ -0,0 +1,107 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+from charms.reactive import when, when_not, hook
+from charms.reactive.flags import set_flag, clear_flag
+from charmhelpers.core.hookenv import (
+    log,
+    metadata,
+    config,
+    network_get,
+    relation_id,
+)
+from charms import layer
+from charmhelpers.core import hookenv
+import traceback
+
+
+@hook("upgrade-charm")
+@when("leadership.is_leader")
+def upgrade():
+    clear_flag("prometheus-k8s.configured")
+
+
+@when("config.changed")
+@when("leadership.is_leader")
+def restart():
+    clear_flag("prometheus-k8s.configured")
+
+
+@when_not("prometheus-k8s.configured")
+@when("leadership.is_leader")
+def configure():
+    layer.status.maintenance("Configuring prometheus container")
+    try:
+        spec = make_pod_spec()
+        log("set pod spec:\n{}".format(spec))
+        layer.caas_base.pod_spec_set(spec)
+        set_flag("prometheus-k8s.configured")
+        layer.status.active("ready")
+
+    except Exception as e:
+        layer.status.blocked("k8s spec failed to deploy: {}".format(e))
+        log(traceback.format_exc(), level=hookenv.ERROR)
+
+
+@when("prometheus-k8s.configured")
+def set_prometheus_active():
+    layer.status.active("ready")
+
+
+@when_not("leadership.is_leader")
+def non_leaders_active():
+    layer.status.active("ready")
+
+
+@when("prometheus-k8s.configured", "endpoint.prometheus.available")
+def send_config(prometheus):
+    layer.status.maintenance("Sending prometheus configuration")
+    cfg = config()
+    try:
+        info = network_get("prometheus", relation_id())
+        log("network info {0}".format(info))
+        host = info.get("ingress-addresses", [""])[0]
+
+        prometheus.configure(hostname=host, port=cfg.get("advertised-port"))
+        clear_flag("endpoint.prometheus.available")
+    except Exception as e:
+        log("Exception sending config: {}".format(e))
+
+
+def make_pod_spec():
+    """Make pod specification for Kubernetes
+
+    Returns:
+        pod_spec: Pod specification for Kubernetes
+    """
+    with open("reactive/spec_template.yaml") as spec_file:
+        pod_spec_template = spec_file.read()
+
+    md = metadata()
+    cfg = config()
+
+    data = {
+        "name": md.get("name"),
+        "docker_image": cfg.get("prometheus-image"),
+        "a_docker_image": cfg.get("alpine-image"),
+    }
+    data.update(cfg)
+    return pod_spec_template % data
diff --git a/installers/charm/prometheus-k8s/reactive/spec_template.yaml b/installers/charm/prometheus-k8s/reactive/spec_template.yaml
new file mode 100644 (file)
index 0000000..018b74f
--- /dev/null
@@ -0,0 +1,68 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+version: 2
+containers:
+  - name: "init-chown-data"
+    image: %(a_docker_image)s
+    imagePullPolicy: "IfNotPresent"
+    command: ["/bin/sh", "-c", "chown -R 65534:65534 /prometheus && while true; do sleep 86400; done"]
+  - name: %(name)s
+    image: %(docker_image)s
+    ports:
+    - containerPort: %(advertised-port)s
+      protocol: TCP
+    config:
+      ALLOW_ANONYMOUS_LOGIN: 'yes'
+    kubernetes:
+      readinessProbe:
+        httpGet:
+          path: /-/ready
+          port: %(advertised-port)s
+        initialDelaySeconds: 10
+        timeoutSeconds: 30
+      livenessProbe:
+        httpGet:
+          path: /-/healthy
+          port: %(advertised-port)s
+        initialDelaySeconds: 30
+        timeoutSeconds: 30
+    command:
+      - "sh"
+      - "-c"
+      - "/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles --web.route-prefix=%(web-subpath)s --web.external-url=http://localhost:%(advertised-port)s%(web-subpath)s"
+    files:
+    - name: config
+      mountPath: /etc/prometheus
+      files:
+        prometheus.yml: |
+          global:
+            scrape_interval:     15s
+            evaluation_interval: 15s
+          alerting:
+            alertmanagers:
+            - static_configs:
+              - targets:
+          rule_files:
+          scrape_configs:
+            - job_name: 'prometheus'
+              static_configs:
+              - targets: ['%(default-target)s']
diff --git a/installers/charm/prometheus-k8s/test-requirements.txt b/installers/charm/prometheus-k8s/test-requirements.txt
new file mode 100644 (file)
index 0000000..b302c2e
--- /dev/null
@@ -0,0 +1,22 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+git+https://github.com/davigar15/zaza.git#egg=zaza
diff --git a/installers/charm/prometheus-k8s/tests/basic_deployment.py b/installers/charm/prometheus-k8s/tests/basic_deployment.py
new file mode 100644 (file)
index 0000000..5adfb24
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/python3
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+import unittest
+import zaza.model as model
+import requests as http
+
+
+def get_prometheus_uri():
+    ip = model.get_status().applications["prometheus-k8s"]["public-address"]
+    port = 9090
+    return "http://{}:{}".format(ip, port)
+
+
+class BasicDeployment(unittest.TestCase):
+    def test_get_prometheus_uri(self):
+        get_prometheus_uri()
+
+    def test_prometheus_get_series(self):
+        prometheus_uri = get_prometheus_uri()
+        body = http.get("{}/api/v1/series?match[]=up".format(prometheus_uri))
+        self.assertEqual(body.status_code, 200)
+
+    def test_prometheus_get_labels(self):
+        prometheus_uri = get_prometheus_uri()
+        body = http.get("{}/api/v1/labels".format(prometheus_uri))
+        self.assertEqual(body.status_code, 200)
+
+    def test_prometheus_get_targets(self):
+        prometheus_uri = get_prometheus_uri()
+        body = http.get("{}/api/v1/targets".format(prometheus_uri))
+        self.assertEqual(body.status_code, 200)
+
+    def test_prometheus_get_alerts(self):
+        prometheus_uri = get_prometheus_uri()
+        body = http.get("{}/api/v1/alerts".format(prometheus_uri))
+        self.assertEqual(body.status_code, 200)
+
+    def test_prometheus_get_status_config(self):
+        prometheus_uri = get_prometheus_uri()
+        body = http.get("{}/api/v1/status/config".format(prometheus_uri))
+        self.assertEqual(body.status_code, 200)
diff --git a/installers/charm/prometheus-k8s/tests/bundles/prometheus-ha.yaml b/installers/charm/prometheus-k8s/tests/bundles/prometheus-ha.yaml
new file mode 100644 (file)
index 0000000..fa66166
--- /dev/null
@@ -0,0 +1,31 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+bundle: kubernetes
+applications:
+  prometheus-k8s:
+    charm: '../../release'
+    scale: 2
+    options:
+      default-target: "mon-k8s:8000"
+    series: kubernetes
+    storage:
+      database: 50M
diff --git a/installers/charm/prometheus-k8s/tests/bundles/prometheus.yaml b/installers/charm/prometheus-k8s/tests/bundles/prometheus.yaml
new file mode 100644 (file)
index 0000000..957cabd
--- /dev/null
@@ -0,0 +1,31 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+bundle: kubernetes
+applications:
+  prometheus-k8s:
+    charm: '../../release'
+    scale: 1
+    options:
+      default-target: "mon-k8s:8000"
+    series: kubernetes
+    storage:
+      database: 50M
diff --git a/installers/charm/prometheus-k8s/tests/tests.yaml b/installers/charm/prometheus-k8s/tests/tests.yaml
new file mode 100644 (file)
index 0000000..f5581a3
--- /dev/null
@@ -0,0 +1,28 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+gate_bundles:
+  - prometheus
+  - prometheus-ha
+smoke_bundles:
+  - prometheus
+tests:
+  - tests.basic_deployment.BasicDeployment
diff --git a/installers/charm/prometheus-k8s/tox.ini b/installers/charm/prometheus-k8s/tox.ini
new file mode 100644 (file)
index 0000000..c242072
--- /dev/null
@@ -0,0 +1,82 @@
+# Copyright 2021 Canonical Ltd.
+#
+# 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.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: legal@canonical.com
+#
+# To get in touch with the maintainers, please contact:
+# osm-charmers@lists.launchpad.net
+##
+
+[tox]
+envlist = pep8
+skipsdist = True
+
+[testenv]
+setenv = VIRTUAL_ENV={envdir}
+         PYTHONHASHSEED=0
+whitelist_externals = juju
+passenv = HOME TERM CS_API_* OS_* AMULET_*
+deps = -r{toxinidir}/test-requirements.txt
+install_command =
+  pip install {opts} {packages}
+
+[testenv:build]
+basepython = python3
+passenv=HTTP_PROXY HTTPS_PROXY NO_PROXY
+setenv = CHARM_LAYERS_DIR = /tmp
+whitelist_externals = git
+                      charm
+                      rm
+                      mv
+commands =
+    rm -rf /tmp/canonical-osm /tmp/osm-common
+    rm -rf release/
+    git clone https://git.launchpad.net/charm-osm-common /tmp/osm-common
+    charm build . --build-dir /tmp
+    mv /tmp/prometheus-k8s/ release/
+
+[testenv:black]
+basepython = python3
+deps =
+    black
+    yamllint
+    flake8
+commands =
+    black --check --diff .
+    yamllint .
+    flake8 reactive/ --max-line-length=88
+    flake8 tests/ --max-line-length=88
+
+[testenv:pep8]
+basepython = python3
+deps=charm-tools
+commands = charm-proof
+
+[testenv:func-noop]
+basepython = python3
+commands =
+    true
+
+[testenv:func]
+basepython = python3
+commands = functest-run-suite
+
+
+[testenv:func-smoke]
+basepython = python3
+commands = functest-run-suite --keep-model --smoke
+
+[testenv:venv]
+commands = {posargs}