Skip to content

Commit 0208871

Browse files
Refactor metrics.proto file
This commit refactors the metrics proto files to be more modular and easier to maintain. The metrics proto files are now split into two files: `metric_sample.proto` and `bounds.proto`. The former contains the definition of the `MetricSample` message, while the latter contains the definition of the `Bounds` message. The files have also been moved into a new directory `metrics`, establishing their package name as `frequenz.api.common.v1.metrics`. Signed-off-by: Tiyash Basu <[email protected]>
1 parent 736198c commit 0208871

File tree

6 files changed

+39
-26
lines changed

6 files changed

+39
-26
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Definitions for bounds.
2+
//
3+
// Copyright:
4+
// Copyright 2023 Frequenz Energy-as-a-Service GmbH
5+
//
6+
// License:
7+
// MIT
8+
9+
syntax = "proto3";
10+
11+
package frequenz.api.common.v1.metrics;
12+
13+
// A set of lower and upper bounds for any metric.
14+
// The units of the bounds are always the same as the related metric.
15+
message Bounds {
16+
// The lower bound.
17+
// If absent, there is no lower bound.
18+
optional float lower = 1;
19+
20+
// The upper bound.
21+
// If absent, there is no upper bound.
22+
optional float upper = 2;
23+
}

proto/frequenz/api/common/v1/metrics/electrical.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ syntax = "proto3";
1010

1111
package frequenz.api.common.v1.metrics.electrical;
1212

13-
import "frequenz/api/common/v1/metrics.proto";
13+
import "frequenz/api/common/v1/metrics/metric_sample.proto";
1414

1515
// Metrics of a DC electrical connection.
1616
message DC {

proto/frequenz/api/common/v1/metrics.proto renamed to proto/frequenz/api/common/v1/metrics/metric_sample.proto

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Metrics & bounds definitions.
1+
// Metrics definitions.
22
//
33
// Copyright:
44
// Copyright 2023 Frequenz Energy-as-a-Service GmbH
@@ -10,19 +10,9 @@ syntax = "proto3";
1010

1111
package frequenz.api.common.v1.metrics;
1212

13-
import "google/protobuf/timestamp.proto";
14-
15-
// A set of lower and upper bounds for any metric.
16-
// The units of the bounds are always the same as the related metric.
17-
message Bounds {
18-
// The lower bound.
19-
// If absent, there is no lower bound.
20-
optional float lower = 1;
13+
import "frequenz/api/common/v1/metrics/bounds.proto";
2114

22-
// The upper bound.
23-
// If absent, there is no upper bound.
24-
optional float upper = 2;
25-
}
15+
import "google/protobuf/timestamp.proto";
2616

2717
// Represents a single sample of a specific metric, the value of which is either
2818
// measured or derived at a particular time.

proto/frequenz/api/common/v1/microgrid/components/components.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ syntax = "proto3";
1010

1111
package frequenz.api.common.v1.microgrid.components;
1212

13-
import "frequenz/api/common/v1/metrics.proto";
13+
import "frequenz/api/common/v1/metrics/metric_sample.proto";
1414
import "frequenz/api/common/v1/microgrid/components/battery.proto";
1515
import "frequenz/api/common/v1/microgrid/components/ev_charger.proto";
1616
import "frequenz/api/common/v1/microgrid/components/fuse.proto";

proto/frequenz/api/common/v1/microgrid/sensors/sensors.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ syntax = "proto3";
1010

1111
package frequenz.api.common.v1.microgrid.sensors;
1212

13-
import "frequenz/api/common/v1/metrics.proto";
13+
import "frequenz/api/common/v1/metrics/metric_sample.proto";
1414
import "frequenz/api/common/v1/microgrid/lifetime.proto";
1515

1616
import "google/protobuf/timestamp.proto";

pytests/test_common.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@ def test_package_import() -> None:
1212
assert v1 is not None
1313

1414

15-
def test_module_import_metrics() -> None:
15+
def test_module_import_metrics_electrical() -> None:
1616
"""Test that the modules can be imported."""
1717
# pylint: disable=import-outside-toplevel
18-
from frequenz.api.common.v1 import metrics_pb2
18+
from frequenz.api.common.v1.metrics import electrical_pb2
1919

20-
assert metrics_pb2 is not None
20+
assert electrical_pb2 is not None
2121

2222
# pylint: disable=import-outside-toplevel
23-
from frequenz.api.common.v1 import metrics_pb2_grpc
23+
from frequenz.api.common.v1.metrics import electrical_pb2_grpc
2424

25-
assert metrics_pb2_grpc is not None
25+
assert electrical_pb2_grpc is not None
2626

2727

28-
def test_module_import_metrics_electrical() -> None:
28+
def test_module_import_metrics_bounds() -> None:
2929
"""Test that the modules can be imported."""
3030
# pylint: disable=import-outside-toplevel
31-
from frequenz.api.common.v1.metrics import electrical_pb2
31+
from frequenz.api.common.v1.metrics import bounds_pb2
3232

33-
assert electrical_pb2 is not None
33+
assert bounds_pb2 is not None
3434

3535
# pylint: disable=import-outside-toplevel
36-
from frequenz.api.common.v1.metrics import electrical_pb2_grpc
36+
from frequenz.api.common.v1.metrics import bounds_pb2_grpc
3737

38-
assert electrical_pb2_grpc is not None
38+
assert bounds_pb2_grpc is not None
3939

4040

4141
def test_module_import_grid() -> None:

0 commit comments

Comments
 (0)