-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathconfig.py
More file actions
126 lines (110 loc) · 4.85 KB
/
config.py
File metadata and controls
126 lines (110 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Copyright Istio Authors
#
# 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.
"""Read runner configuration from a dict or TOML."""
from typing import Any, Dict, List, Optional
import toml
class RunnerConfig:
"""Represents the intermediary between a config file"""
def __init__(self, topology_paths: List[str], environments: List[str],
istio_archive_url: str, cluster_project_id: str,
cluster_name: str, cluster_zones: List[str],
cluster_version: str, server_machine_type: str,
server_disk_size_gb: int, server_num_nodes: int,
server_image: str, client_machine_type: str,
client_disk_size_gb: int, client_image: str,
client_qps: Optional[int], client_duration: str,
client_num_conc_conns: int) -> None:
self.topology_paths = topology_paths
self.environments = environments
self.istio_archive_url = istio_archive_url
self.cluster_project_id = cluster_project_id
self.cluster_name = cluster_name
self.cluster_zones = cluster_zones
self.cluster_version = cluster_version
self.server_machine_type = server_machine_type
self.server_disk_size_gb = server_disk_size_gb
self.server_num_nodes = server_num_nodes
self.server_image = server_image
self.client_machine_type = client_machine_type
self.client_disk_size_gb = client_disk_size_gb
self.client_image = client_image
self.client_qps = client_qps
self.client_duration = client_duration
self.client_num_conc_conns = client_num_conc_conns
def labels(self) -> Dict[str, str]:
"""Returns the static labels for Prometheus for this configuration."""
return {
'istio_archive_url': self.istio_archive_url,
'cluster_version': self.cluster_version,
'cluster_zones': self.cluster_zones,
'server_machine_type': self.server_machine_type,
'server_disk_size_gb': str(self.server_disk_size_gb),
'server_num_nodes': str(self.server_num_nodes),
'server_image': self.server_image,
'client_machine_type': self.client_machine_type,
'client_disk_size_gb': str(self.client_disk_size_gb),
'client_image': self.client_image,
'client_qps': str(self.client_qps),
'client_duration': self.client_duration,
'client_num_concurrent_connections':
str(self.client_num_conc_conns),
}
def from_dict(d: Dict[str, Any]) -> RunnerConfig:
topology_paths = d.get('topology_paths', [])
environments = d.get('environments', [])
istio = d['istio']
istio_archive_url = istio['archive_url']
cluster = d['cluster']
cluster_project_id = cluster['project_id']
cluster_name = cluster['name']
cluster_zones = cluster['zones']
cluster_version = cluster['version']
server = d['server']
server_machine_type = server['machine_type']
server_disk_size_gb = server['disk_size_gb']
server_num_nodes = server['num_nodes']
server_image = server['image']
client = d['client']
client_machine_type = client['machine_type']
client_disk_size_gb = client['disk_size_gb']
client_image = client['image']
client_qps = client['qps']
if client_qps == 'max':
client_qps = None
else:
# Must coerce into integer, otherwise not a valid QPS.
client_qps = int(client_qps)
client_duration = client['duration']
client_num_conc_conns = client['num_concurrent_connections']
return RunnerConfig(
topology_paths=topology_paths,
environments=environments,
istio_archive_url=istio_archive_url,
cluster_project_id=cluster_project_id,
cluster_name=cluster_name,
cluster_zones=cluster_zones,
cluster_version=cluster_version,
server_machine_type=server_machine_type,
server_disk_size_gb=server_disk_size_gb,
server_image=server_image,
server_num_nodes=server_num_nodes,
client_machine_type=client_machine_type,
client_disk_size_gb=client_disk_size_gb,
client_image=client_image,
client_qps=client_qps,
client_duration=client_duration,
client_num_conc_conns=client_num_conc_conns)
def from_toml_file(path: str) -> RunnerConfig:
d = toml.load(path)
return from_dict(d)