Skip to content

Commit

Permalink
Merge pull request #64 from nautobot/develop
Browse files Browse the repository at this point in the history
Release 3.0.0
  • Loading branch information
glennmatthews authored Sep 29, 2023
2 parents 5406214 + 2d82b1a commit d34ba0a
Show file tree
Hide file tree
Showing 18 changed files with 382 additions and 608 deletions.
38 changes: 26 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on: # yamllint disable

jobs:
black:
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
env:
INVOKE_NAUTOBOT_CAPACITY_METRICS_LOCAL: "True"
steps:
Expand All @@ -17,7 +17,7 @@ jobs:
- name: "Linting: black"
run: "poetry run invoke black"
bandit:
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
env:
INVOKE_NAUTOBOT_CAPACITY_METRICS_LOCAL: "True"
steps:
Expand All @@ -30,7 +30,7 @@ jobs:
needs:
- "black"
pydocstyle:
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
env:
INVOKE_NAUTOBOT_CAPACITY_METRICS_LOCAL: "True"
steps:
Expand All @@ -43,7 +43,7 @@ jobs:
needs:
- "black"
flake8:
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
env:
INVOKE_NAUTOBOT_CAPACITY_METRICS_LOCAL: "True"
steps:
Expand All @@ -56,7 +56,7 @@ jobs:
needs:
- "black"
yamllint:
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
env:
INVOKE_NAUTOBOT_CAPACITY_METRICS_LOCAL: "True"
steps:
Expand All @@ -69,7 +69,7 @@ jobs:
needs:
- "black"
build:
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
Expand All @@ -85,7 +85,7 @@ jobs:
- "flake8"
- "yamllint"
pylint:
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v2"
Expand All @@ -103,9 +103,23 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
nautobot-version: ["1.6.2"]
runs-on: "ubuntu-20.04"
python-version: ["3.8"]
db-backend: ["postgresql", "mysql"]
nautobot-version: ["2.0.0"]
# The include is a method to limit the amount of jobs ran. This essentially
# means that in addition to standard postgres and stable, also the lowest
# supported version and with mysql
include:
- python-version: "3.11"
db-backend: "postgresql"
nautobot-version: "2.0.0"
- python-version: "3.11"
db-backend: "postgresql"
nautobot-version: "stable"
- python-version: "3.11"
db-backend: "mysql"
nautobot-version: "stable"
runs-on: "ubuntu-22.04"
env:
INVOKE_NAUTOBOT_CAPACITY_METRICS_PYTHON_VER: "${{ matrix.python-version }}"
INVOKE_NAUTOBOT_CAPACITY_METRICS_NAUTOBOT_VER: "${{ matrix.nautobot-version }}"
Expand All @@ -124,7 +138,7 @@ jobs:
- "pylint"
publish_gh:
name: "Publish to GitHub"
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
if: "startsWith(github.ref, 'refs/tags/v')"
steps:
- name: "Check out repository code"
Expand Down Expand Up @@ -153,7 +167,7 @@ jobs:
- "unittest"
publish_pypi:
name: "Push Package to PyPI"
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-22.04"
if: "startsWith(github.ref, 'refs/tags/v')"
steps:
- name: "Check out repository code"
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Changelog

## 3.0.0

Compatible with Nautobot version >=2.0.0.

## 3.0.0-rc.2

Compatible with and only with Nautobot version 2.0.0-rc.2.

## 3.0.0-beta.1

Compatible with and only with Nautobot version 2.0.0-beta.2.

### Added

- Possibility to use `invoke logs` to view container logs (#52)

### Changed

- Added compatibility with Nautobot 2.0, removed Nautobot 1.0 compatibility (#52)
- Updated Ubuntu version in CI to 22.04

### Removed

- Metrics for (deprecated) RQ workers (#52)
- Django management command for RQ worker metrics (#52)

## 2.1.1

Re-release due to publishing issues.
Expand Down
2 changes: 2 additions & 0 deletions development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ RUN pip install -c constraints.txt -e .
RUN pip install -c constraints.txt -r poetry_freeze_dev.txt

COPY development/nautobot_config.py ${NAUTOBOT_ROOT}/nautobot_config.py

USER root
# !!! USE CAUTION WHEN MODIFYING LINES ABOVE
3 changes: 1 addition & 2 deletions development/docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ services:
depends_on:
- "postgres"
- "redis"
<<: *nautobot-build
<<: *nautobot-base
<<: [*nautobot-build, *nautobot-base]

worker:
entrypoint: "nautobot-server rqworker_metrics"
Expand Down
3 changes: 3 additions & 0 deletions development/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ services:
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
- "./example_jobs:/opt/nautobot/jobs"
worker:
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
- "./example_jobs:/opt/nautobot/jobs"

celery:
volumes:
- "./nautobot_config.py:/opt/nautobot/nautobot_config.py"
- "../:/source"
- "./example_jobs:/opt/nautobot/jobs"
22 changes: 22 additions & 0 deletions development/example_jobs/test_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""This script contains an example of a job about users."""
import time

from nautobot.core.celery import register_jobs
from nautobot.extras.jobs import Job, BooleanVar, IntegerVar


class TestJob(Job):
"""Job to test metrics with."""

sleep = IntegerVar(description="How long this job should sleep.")
fail = BooleanVar(description="Whether this job should fail.")

def run(self, sleep, fail):
self.logger.warning(f"Sleeping {sleep} seconds.")
time.sleep(sleep)
if fail:
raise ValueError("I am supposed to fail!")
return


register_jobs(TestJob)
17 changes: 0 additions & 17 deletions development/example_jobs/users.py

This file was deleted.

8 changes: 4 additions & 4 deletions nautobot_capacity_metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__version__ = "1.1.1"

from nautobot.extras.plugins import PluginConfig
from nautobot.extras.plugins import NautobotAppConfig

# Registry of functions that can generate additional application metrics
# All functions in the registry should take no argument and return an Iterator (or list) of prometheus Metric Object
Expand All @@ -24,7 +24,7 @@ def register_metric_func(func):
__REGISTRY__.append(func)


class MetricsExtConfig(PluginConfig):
class MetricsExtConfig(NautobotAppConfig):
"""Plugin configuration for the nautobot_capacity_metrics plugin."""

name = "nautobot_capacity_metrics"
Expand All @@ -35,8 +35,8 @@ class MetricsExtConfig(PluginConfig):
description = "Lightweight Nautobot App to expose additional metrics as Prometheus endpoints. Includes exposing Nautobot object data and metrics that can be collected and later viewed in Visualization tools."
base_url = "capacity-metrics"
required_settings = []
min_version = "1.4.0"
max_version = "1.9999"
min_version = "2.0.0"
max_version = "2.99"
default_settings = {
"app_metrics": {
"models": {
Expand Down
3 changes: 0 additions & 3 deletions nautobot_capacity_metrics/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@
urlpatterns = [
path("app-metrics", views.AppMetricsView, name="nautobot_capacity_metrics_app_view"),
]

if "queues" in PLUGIN_SETTINGS and PLUGIN_SETTINGS["queues"]:
urlpatterns.append(path("rq-metrics", views.QueueMetricsView, name="nautobot_capacity_metrics_rq_view"))
45 changes: 6 additions & 39 deletions nautobot_capacity_metrics/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from django.conf import settings
from django.http import HttpResponse

from nautobot.extras.models import GitRepository
import prometheus_client
from prometheus_client.core import CollectorRegistry, GaugeMetricFamily

Expand All @@ -14,7 +13,6 @@
collect_extras_metric,
metric_jobs,
metric_models,
metric_rq,
metric_versions,
)

Expand All @@ -30,11 +28,11 @@ def collect(self): # pylint: disable=no-self-use
start = time.time()

if "gitrepositories" in PLUGIN_SETTINGS and PLUGIN_SETTINGS["gitrepositories"]:
for metric in metric_jobs(job_model=GitRepository):
for metric in metric_jobs(type_of_job="git_repository"):
yield metric

if "jobs" in PLUGIN_SETTINGS and PLUGIN_SETTINGS["jobs"]:
for metric in metric_jobs():
for metric in metric_jobs(type_of_job="job"):
yield metric

if "models" in PLUGIN_SETTINGS:
Expand Down Expand Up @@ -65,41 +63,10 @@ def collect(self): # pylint: disable=no-self-use
yield gauge


class QueueMetricsCollector:
"""Collector class for collecting django rq related metrics metrics."""

def collect(self): # pylint: disable=no-self-use
"""Collect metrics for all plugins and extras."""
start = time.time()
for metric in metric_rq():
yield metric

gauge = GaugeMetricFamily(
"nautobot_rq_metrics_processing_ms", "Time in ms to generate the app metrics endpoint"
)
duration = time.time() - start
gauge.add_metric([], format(duration * 1000, ".5f"))
yield gauge


def ExportToDjangoView(request, view=""): # pylint: disable=invalid-name
"""Exports /api/plugins/capacity-metrics/[app|rq]-metrics as a Django view."""
def AppMetricsView(request): # pylint: disable=invalid-name
"""Exports /api/plugins/capacity-metrics/app-metrics as a Django view."""
registry = CollectorRegistry()
if view == "rq-metrics":
collector = QueueMetricsCollector()
registry.register(collector)
elif view == "app-metrics":
collector = AppMetricsCollector()
registry.register(collector)
collector = AppMetricsCollector()
registry.register(collector)
metrics_page = prometheus_client.generate_latest(registry)
return HttpResponse(metrics_page, content_type=prometheus_client.CONTENT_TYPE_LATEST)


def QueueMetricsView(request): # pylint: disable=invalid-name
"""Exports /api/plugins/capacity-metrics/rq-metrics as a Django view."""
return ExportToDjangoView(request, view="rq-metrics")


def AppMetricsView(request): # pylint: disable=invalid-name
"""Exports /api/plugins/capacity-metrics/app-metrics as a Django view."""
return ExportToDjangoView(request, view="app-metrics")
1 change: 0 additions & 1 deletion nautobot_capacity_metrics/management/__init__.py

This file was deleted.

1 change: 0 additions & 1 deletion nautobot_capacity_metrics/management/commands/__init__.py

This file was deleted.

41 changes: 0 additions & 41 deletions nautobot_capacity_metrics/management/commands/rqworker_metrics.py

This file was deleted.

Loading

0 comments on commit d34ba0a

Please sign in to comment.