Commit b4f35c5b authored by Carlos Natalino's avatar Carlos Natalino
Browse files

Merge branch 'feat/local-testing' into feat/optical-cybersecurity

parents b70986e7 fd843b45
Loading
Loading
Loading
Loading
+74 −34
Original line number Diff line number Diff line
@@ -13,13 +13,14 @@
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
  name: monitoringservice
  name: monitoringdb
spec:
  selector:
    matchLabels:
      app: monitoringservice
  serviceName: "monitoringservice"
  replicas: 1
  template:
    metadata:
@@ -32,35 +33,50 @@ spec:
      - name: metricsdb
        image: questdb/questdb
        ports:
        - containerPort: 9000
        - containerPort: 9009
        - containerPort: 9003
        - name: http
          containerPort: 9000
          protocol: TCP
        - name: influxdb
          containerPort: 9009
          protocol: TCP
        - name: postgre
          containerPort: 8812
          protocol: TCP
        env:
        - name: QDB_CAIRO_COMMIT_LAG
          value: "1000"
        - name: QDB_CAIRO_MAX_UNCOMMITTED_ROWS
          value: "100000"
        # readinessProbe:
        #   exec:
        #     command: ["curl", "-XGET", "localhost:9000"]
        # livenessProbe:
        #   exec:
        #     command: ["curl", "-XGET", "localhost:9003/metrics"]
        resources:
          requests:
            cpu: 250m
            memory: 512Mi
          limits:
            cpu: 700m
            memory: 1024Mi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: monitoringserver
spec:
  selector:
    matchLabels:
      app: monitoringservice
  replicas: 1
  template:
    metadata:
      labels:
        app: monitoringservice
    spec:
      terminationGracePeriodSeconds: 5
      restartPolicy: Always
      containers:
      - name: server
        image: registry.gitlab.com/teraflow-h2020/controller/monitoring:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 7070
        - name: grpc
          containerPort: 7070
          protocol: TCP
        env:
        - name: LOG_LEVEL
          value: "INFO"
        - name: METRICSDB_HOSTNAME
          value: "localhost"
          value: "monitoringservice"
        - name: METRICSDB_ILP_PORT
          value: "9009"
        - name: METRICSDB_REST_PORT
@@ -68,19 +84,13 @@ spec:
        - name: METRICSDB_TABLE
          value: "monitoring"
        readinessProbe:
          exec:
            command: ["/bin/grpc_health_probe", "-addr=:7070"]
          grpc:
            port: 7070
          initialDelaySeconds: 5
        livenessProbe:
          exec:
            command: ["/bin/grpc_health_probe", "-addr=:7070"]
        resources:
          requests:
            cpu: 250m
            memory: 512Mi
          limits:
            cpu: 700m
            memory: 1024Mi

          grpc:
            port: 7070
          initialDelaySeconds: 10
---
apiVersion: v1
kind: Service
@@ -95,7 +105,37 @@ spec:
    protocol: TCP
    port: 7070
    targetPort: 7070
  - name: questdb
  - name: http
    protocol: TCP
    port: 9000
    targetPort: 9000
  - name: influxdb
    protocol: TCP
    port: 9009
    targetPort: 9009
  - name: postgre
    protocol: TCP
    port: 8812
    targetPort: 8812

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: access-monitoring
spec:
  podSelector:
    matchLabels:
      app: monitoringservice 
  ingress:
  - from: []
    ports:
    - port: 7070
    - port: 8812
  - from:
    - podSelector:
        matchLabels:
          app: monitoringservice
    ports:
    - port: 9009
    - port: 9000
+16 −13
Original line number Diff line number Diff line
@@ -17,12 +17,15 @@ import socket
import requests
import json
import sys
import logging

LOGGER = logging.getLogger(__name__)

class MetricsDB():
  def __init__(self, host, ilp_port, rest_port, table):
    self.socket=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.host=host
      self.ilp_port=ilp_port
    self.ilp_port=int(ilp_port)
    self.rest_port=rest_port
    self.table=table

@@ -47,6 +50,6 @@ class MetricsDB():
    try:
        response = requests.get(url, params=query_params)
        json_response = json.loads(response.text)
          print(json_response)
        LOGGER.info(json_response)
    except requests.exceptions.RequestException as e:
          print(f'Error: {e}', file=sys.stderr)
        LOGGER.info(f'Error: {e}', file=sys.stderr)
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ class MonitoringServiceServicerImpl(MonitoringServiceServicer):

        # Set metrics_db client
        self.metrics_db = MetricsDBTools.MetricsDB(METRICSDB_HOSTNAME,METRICSDB_ILP_PORT,METRICSDB_REST_PORT,METRICSDB_TABLE)
        LOGGER.info('MetricsDB initialized')

    # SetKpi (SetKpiRequest) returns (KpiId) {}
    def SetKpi(