Commit 2048e5ed authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Improvements in Monitoring:

- Arranged commit before merge
- Replaced string-based timestamps by context.Timestamp
- Created helper functions to convert timestamps string from/to float
- Arranged requirements to meet dependencies of converter functions
parent afd3e856
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,3 +6,4 @@ prometheus-client==0.13.0
protobuf==3.20.*
pytest==6.2.5
pytest-benchmark==3.4.1
python-dateutil==2.8.2
+76 −73
Original line number Diff line number Diff line
@@ -83,8 +83,8 @@ message KpiQuery {
  float             monitoring_window_s = 2;
  float             sampling_rate_s     = 3;
  uint32            last_n_samples      = 4;  // used when you want something like "get the last N many samples
  string start_date         = 5;  // used when you want something like "get the samples since X date/time"
  string end_date           = 6;  // used when you want something like "get the samples until X date/time"
  context.Timestamp start_timestamp     = 5;  // used when you want something like "get the samples since X date/time"
  context.Timestamp end_timestamp       = 6;  // used when you want something like "get the samples until X date/time"
  // Pending add field to reflect Available Device Protocols
}

@@ -94,7 +94,7 @@ message KpiId {

message Kpi {
  KpiId             kpi_id    = 1;
  string timestamp  = 2;
  context.Timestamp timestamp = 2;
  KpiValue          kpi_value = 3;
}

@@ -106,10 +106,13 @@ message KpiValueRange {

message KpiValue {
  oneof value {
    uint32 intVal     = 1;
    float floatVal    = 2;
    string stringVal  = 3;
    bool boolVal      = 4;
    int32  int32Val  = 1;
    uint32 uint32Val = 2;
    int64  int64Val  = 3;
    uint64 uint64Val = 4;
    float  floatVal  = 5;
    string stringVal = 6;
    bool   boolVal   = 7;
  }
}

@@ -125,8 +128,8 @@ message SubsDescriptor{
  KpiId             kpi_id              = 1;
  float             sampling_duration_s = 2;
  float             sampling_interval_s = 3;
  string start_date         = 4;  // used when you want something like "get the samples since X date/time"
  string end_date           = 5;  // used when you want something like "get the samples until X date/time"
  context.Timestamp start_timestamp     = 4;  // used when you want something like "get the samples since X date/time"
  context.Timestamp end_timestamp       = 5;  // used when you want something like "get the samples until X date/time"
  // Pending add field to reflect Available Device Protocols
}

@@ -148,7 +151,7 @@ message AlarmDescriptor {
  string            name              = 2;
  KpiId             kpi_id            = 3;
  KpiValueRange     kpi_value_range   = 4;
  context.Timestamp timestamp   = 5; // Check context
  context.Timestamp timestamp         = 5;
}

message AlarmID{
@@ -165,7 +168,7 @@ message AlarmResponse {
  AlarmID           alarm_id  = 1;
  string            text      = 2;
  KpiValue          kpi_value = 3;
  context.Timestamp timestamp   = 4; // Check context
  context.Timestamp timestamp = 4;
}

message AlarmIDList {

src/common/proto

0 → 120000
+1 −0
Original line number Diff line number Diff line
../../proto/src/python
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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.
+11 −0
Original line number Diff line number Diff line
import dateutil.parser
from datetime import datetime, timezone

def timestamp_string_to_float(str_timestamp : str) -> float:
    return datetime.timestamp(dateutil.parser.isoparse(str_timestamp))

def timestamp_float_to_string(flt_timestamp : float) -> str:
    return datetime.utcfromtimestamp(flt_timestamp).isoformat() + 'Z'

def timestamp_utcnow_to_float() -> float:
    return datetime.timestamp(datetime.now(tz=timezone.utc))
Loading