Skip to content

Commit aaf0d2b

Browse files
committed
Merge branch 'main' of github.com:drycc/controller into main
2 parents 219c3cf + ed123a0 commit aaf0d2b

9 files changed

Lines changed: 215 additions & 28 deletions

File tree

.drone/drone.yml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
kind: pipeline
2+
type: docker
3+
name: linux-amd64
4+
5+
platform:
6+
arch: amd64
7+
os: linux
8+
9+
steps:
10+
- name: test
11+
image: docker.io/drycc/go-dev
12+
pull: if-not-exists
13+
privileged: true
14+
commands:
15+
- make test docker-build-test upload-coverage
16+
environment:
17+
VERSION: ${DRONE_TAG:-latest}-linux-amd64
18+
DEV_REGISTRY: ${DEV_REGISTRY:-docker.io}
19+
DRYCC_REGISTRY: ${DRYCC_REGISTRY:-docker.io}
20+
CODECOV_TOKEN:
21+
from_secret: codecov_token
22+
when:
23+
event:
24+
- push
25+
- tag
26+
- pull_request
27+
28+
- name: publish
29+
image: docker.io/drycc/go-dev
30+
pull: if-not-exists
31+
privileged: true
32+
commands:
33+
- echo $DOCKER_PASSWORD | docker login $DRYCC_REGISTRY --username $DOCKER_USERNAME --password-stdin
34+
- make docker-build docker-immutable-push
35+
environment:
36+
VERSION: ${DRONE_TAG:-latest}-linux-amd64
37+
DEV_REGISTRY:
38+
from_secret: dev_registry
39+
DRYCC_REGISTRY:
40+
from_secret: drycc_registry
41+
DOCKER_USERNAME:
42+
from_secret: docker_username
43+
DOCKER_PASSWORD:
44+
from_secret: docker_password
45+
when:
46+
event:
47+
- push
48+
- tag
49+
50+
trigger:
51+
event:
52+
- push
53+
- tag
54+
- pull_request
55+
56+
---
57+
kind: pipeline
58+
type: docker
59+
name: linux-arm64
60+
61+
platform:
62+
arch: arm64
63+
os: linux
64+
65+
steps:
66+
- name: publish
67+
image: docker.io/drycc/go-dev
68+
pull: if-not-exists
69+
privileged: true
70+
commands:
71+
- echo $DOCKER_PASSWORD | docker login $DRYCC_REGISTRY --username $DOCKER_USERNAME --password-stdin
72+
- make docker-build docker-immutable-push
73+
environment:
74+
VERSION: ${DRONE_TAG:-latest}-linux-arm64
75+
DEV_REGISTRY:
76+
from_secret: dev_registry
77+
DRYCC_REGISTRY:
78+
from_secret: drycc_registry
79+
DOCKER_USERNAME:
80+
from_secret: docker_username
81+
DOCKER_PASSWORD:
82+
from_secret: docker_password
83+
84+
trigger:
85+
event:
86+
- push
87+
- tag
88+
89+
---
90+
kind: pipeline
91+
type: docker
92+
name: manifest
93+
94+
steps:
95+
- name: generate manifest
96+
image: docker.io/library/alpine
97+
pull: if-not-exists
98+
commands:
99+
- sed -i "s/docker.io/$${DRYCC_REGISTRY}/g" .drone/manifest.tmpl
100+
environment:
101+
DRYCC_REGISTRY:
102+
from_secret: drycc_registry
103+
104+
- name: publish
105+
image: plugins/manifest
106+
settings:
107+
spec: .drone/manifest.tmpl
108+
username:
109+
from_secret: docker_username
110+
password:
111+
from_secret: docker_password
112+
environment:
113+
DEV_REGISTRY:
114+
from_secret: dev_registry
115+
DRYCC_REGISTRY:
116+
from_secret: drycc_registry
117+
118+
trigger:
119+
event:
120+
- push
121+
- tag
122+
123+
depends_on:
124+
- linux-amd64
125+
- linux-arm64
126+
127+
---
128+
kind: pipeline
129+
type: docker
130+
name: chart
131+
132+
steps:
133+
- name: generate chart
134+
image: docker.io/drycc/python-dev
135+
commands:
136+
- IMAGE_TAG=$([ ! -z $DRONE_TAG ] && echo \"${DRONE_TAG:1}\" || echo \"canary\")
137+
- sed -i "s/image_tag:\ \"canary\"/image_tag:\ $IMAGE_TAG/g" charts/controller/values.yaml
138+
- helm package charts/controller --version ${DRONE_TAG:-v1.0.0}
139+
- curl -u $CHARTMUSEUM_USERNAME:$CHARTMUSEUM_PASSWORD -F chart=@controller-${DRONE_TAG:-v1.0.0}.tgz "$CHARTMUSEUM_API/api/$([ -z $DRONE_TAG ] && echo testing || echo stable)/charts"
140+
environment:
141+
CHARTMUSEUM_USERNAME:
142+
from_secret: chartmuseum_username
143+
CHARTMUSEUM_PASSWORD:
144+
from_secret: chartmuseum_password
145+
CHARTMUSEUM_API:
146+
from_secret: chartmuseum_api
147+
148+
trigger:
149+
event:
150+
- push
151+
- tag

.drone/manifest.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
image: docker.io/drycc/controller:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}canary{{/if}}
2+
{{#if build.tags}}
3+
tags:
4+
{{#each build.tags}}
5+
- {{this}}
6+
{{/each}}
7+
{{/if}}
8+
manifests:
9+
-
10+
image: docker.io/drycc/controller:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-amd64
11+
platform:
12+
architecture: amd64
13+
os: linux
14+
-
15+
image: docker.io/drycc/controller:{{#if build.tag}}{{build.tag}}-{{else}}latest-{{/if}}linux-arm64
16+
platform:
17+
architecture: arm64
18+
os: linux

.travis.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Drycc Controller
33

4-
[![Build Status](https://travis-ci.org/drycc/controller.svg?branch=main)](https://travis-ci.org/drycc/controller)
4+
[![Build Status](https://drone.drycc.cc/api/badges/drycc/controller/status.svg)](https://drone.drycc.cc/drycc/controller)
55
[![codecov.io](https://codecov.io/github/drycc/controller/coverage.svg?branch=main)](https://codecov.io/github/drycc/controller?branch=main)
66

77
Drycc (pronounced DAY-iss) Workflow is an open source Platform as a Service (PaaS) that adds a developer-friendly layer to any [Kubernetes](http://kubernetes.io) cluster, making it easy to deploy and manage applications on your own servers.

charts/controller/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ env:
8383
name: database-creds
8484
key: password
8585
- name: DRYCC_DATABASE_URL
86-
value: "postgres://$(DRYCC_DATABASE_USER):$(DRYCC_DATABASE_PASSPORT)@$(DRYCC_DATABASE_SERVICE_HOST):$(DRYCC_DATABASE_SERVICE_PORT)/$(DRYCC_DATABASE_USER)"
86+
value: "postgres://$(DRYCC_DATABASE_USER):$(DRYCC_DATABASE_PASSWORD)@$(DRYCC_DATABASE_SERVICE_HOST):$(DRYCC_DATABASE_SERVICE_PORT)/$(DRYCC_DATABASE_USER)"
8787
{{- end }}
8888
- name: WORKFLOW_NAMESPACE
8989
valueFrom:

rootfs/api/influxdb.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
import threading
2+
import logging
23
from typing import Iterator
34
from contextlib import closing
45
from django.conf import settings
56
from influxdb_client import InfluxDBClient
67
from influxdb_client.client.flux_table import FluxRecord
8+
from influxdb_client.rest import ApiException
79

810
local = threading.local()
11+
logger = logging.getLogger(__name__)
912

1013

1114
def _get_influxdb_client() -> InfluxDBClient:
1215
if not hasattr(local, "influxdb_client"):
1316
local.influxdb_client = InfluxDBClient(
14-
url=settings.INFLUXDB_URL,
15-
token=settings.INFLUXDB_TOKEN,
16-
org=settings.INFLUXDB_ORG
17+
url=settings.DRYCC_INFLUXDB_URL,
18+
token=settings.DRYCC_INFLUXDB_TOKEN,
19+
org=settings.DRYCC_INFLUXDB_ORG
1720
)
1821
return local.influxdb_client
1922

2023

2124
def _query_stream(flux_script: str) -> Iterator[FluxRecord]:
2225
with closing(_get_influxdb_client()) as client:
23-
with closing(client.query_api()) as query_api:
24-
with closing(query_api.query_stream(flux_script)) as records:
25-
yield from records
26+
try:
27+
query_api = client.query_api()
28+
records = query_api.query_stream(flux_script)
29+
except ApiException as e:
30+
logger.exception(e)
31+
yield from []
32+
else:
33+
yield from records
2634

2735

2836
def query_container_count(

rootfs/api/serializers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,13 @@ def update(self, instance, validated_data):
716716
instance.attach_update()
717717
instance.save()
718718
return instance
719+
720+
721+
class MetricSerializer(serializers.Serializer):
722+
import time
723+
now = int(time.time())
724+
default_start = (now - now % 3600) - 3600
725+
default_stop = now - now % 3600
726+
start = serializers.IntegerField(min_value=946656000, max_value=4102416000, required=False, default=default_start) # noqa
727+
stop = serializers.IntegerField(min_value=946656000, max_value=4102416000, required=False, default=default_stop) # noqa
728+
every = serializers.CharField(max_length=50, required=False, default='5m') # noqa

rootfs/api/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,6 @@
155155
views.UserView.as_view({'patch': 'enable'})),
156156
url(r'^users/(?P<username>[\w.@+-]+)/disable/?$',
157157
views.UserView.as_view({'patch': 'disable'})),
158+
url(r'^apps/(?P<id>{})/metrics/(?P<container_type>[a-z0-9]+(\-[a-z0-9]+)*)?$'.format(settings.APP_URL_REGEX), # noqa
159+
views.MetricView.as_view({'get': 'status'})),
158160
]

rootfs/api/views.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ class MetricView(BaseDryccViewSet):
914914
"""Getting monitoring indicators from influxdb"""
915915

916916
def _get_app(self):
917-
app = get_object_or_404(models.App, id=self.kwargs['app_id'])
917+
app = get_object_or_404(models.App, id=self.kwargs['id'])
918918
self.check_object_permissions(self.request, app)
919919
return app
920920

@@ -976,13 +976,22 @@ def status(self, request, **kwargs):
976976
],
977977
}
978978
"""
979-
app_id, container_type = self._get_app().pk, kwargs['container_type']
980-
start, stop, every = kwargs['start'], kwargs['stop'], kwargs["every"]
981-
return {
979+
app_id, container_type = self._get_app().id, kwargs['container_type']
980+
981+
data = serializers.MetricSerializer(data=self.request.query_params)
982+
if not data.is_valid():
983+
return Response(data.errors, status=422)
984+
start, stop, every = data.validated_data['start'], data.validated_data[
985+
'stop'], data.validated_data["every"]
986+
return Response({
982987
"app_id": app_id,
983988
"container_type": container_type,
984-
"container_count": self._get_container_count(app_id, container_type, start, stop),
985-
"cpu_usage_list": self._get_cpus(app_id, container_type, start, stop, every),
986-
"memory": self._get_memory(app_id, container_type, start, stop, every),
987-
"networks": self._get_networks(app_id, container_type, start, stop, every)
988-
}
989+
"container_count": self._get_container_count(
990+
app_id, container_type, start, stop),
991+
"cpu_usage_list": self._get_cpus(
992+
app_id, container_type, start, stop, every),
993+
"memory": self._get_memory(
994+
app_id, container_type, start, stop, every),
995+
"networks": self._get_networks(
996+
app_id, container_type, start, stop, every)
997+
})

0 commit comments

Comments
 (0)