flexmetric 0.4.0__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,32 +15,54 @@ def add_update_metric_route():
15
15
  @app.route("/update_metric", methods=["POST"])
16
16
  def update_metric():
17
17
  try:
18
- data = request.get_json()
18
+ data = request.get_json(force=True)
19
19
 
20
- # Validate top-level structure
21
- if not data or "result" not in data or "labels" not in data or "main_label" not in data:
22
- return jsonify({"status": "invalid structure"}), 400
20
+ # Top-level validation
21
+ if not isinstance(data, dict):
22
+ return jsonify({"status": "invalid structure", "error": "Top-level JSON must be an object"}), 400
23
23
 
24
- result = data["result"]
25
- labels = data["labels"]
26
- main_label = data["main_label"]
24
+ required_keys = {"result", "labels", "main_label"}
25
+ if not required_keys.issubset(data):
26
+ return jsonify({"status": "invalid structure", "error": f"Missing keys: {required_keys - set(data)}"}), 400
27
27
 
28
- # Validate types
29
- if not isinstance(result, list) or not isinstance(labels, list) or not isinstance(main_label, str):
30
- return jsonify({"status": "invalid types"}), 400
28
+ result = data.get("result")
29
+ labels = data.get("labels")
30
+ main_label = data.get("main_label")
31
31
 
32
- for item in result:
32
+ # Type validation
33
+ if not isinstance(result, list) or not all(isinstance(item, dict) for item in result):
34
+ return jsonify({"status": "invalid result", "error": "Result must be a list of dictionaries"}), 400
35
+
36
+ if not isinstance(labels, list) or not all(isinstance(label, str) for label in labels):
37
+ return jsonify({"status": "invalid labels", "error": "Labels must be a list of strings"}), 400
38
+
39
+ if not isinstance(main_label, str) or not main_label.strip():
40
+ return jsonify({"status": "invalid main_label", "error": "main_label must be a non-empty string"}), 400
41
+
42
+ for idx, item in enumerate(result):
33
43
  if "label" not in item or "value" not in item:
34
- return jsonify({"status": "invalid result item"}), 400
35
- if not isinstance(item["label"], list):
36
- return jsonify({"status": "label must be list"}), 400
44
+ return jsonify({"status": "invalid result item", "error": f"Item {idx} missing 'label' or 'value'"}), 400
45
+
46
+ label_values = item["label"]
47
+ value = item["value"]
48
+
49
+ if not isinstance(label_values, list) or not all(isinstance(lv, str) for lv in label_values):
50
+ return jsonify({"status": "invalid label", "error": f"Item {idx} 'label' must be list of strings"}), 400
51
+
52
+ if len(label_values) != len(labels):
53
+ return jsonify({
54
+ "status": "label count mismatch",
55
+ "error": f"Item {idx} label count ({len(label_values)}) does not match labels length ({len(labels)})"
56
+ }), 400
37
57
 
38
- if len(item["label"]) != len(labels):
39
- return jsonify({"status": "label count mismatch"}), 400
58
+ try:
59
+ float(value) # Validate numeric value
60
+ except (ValueError, TypeError):
61
+ return jsonify({"status": "invalid value", "error": f"Item {idx} value must be numeric"}), 400
40
62
 
41
- # If everything is valid, queue the data
63
+ # If all checks pass, queue the metric
42
64
  metric_queue.put(data)
43
- print(metric_queue)
65
+ print("Queued:", data)
44
66
 
45
67
  return jsonify({"status": "success"}), 200
46
68
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexmetric
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: A secure flexible Prometheus exporter for commands, databases, functions, and scripts.
5
5
  Home-page: https://github.com/nikhillingadhal1999/flexmetric
6
6
  Author: Nikhil Lingadhal
@@ -138,15 +138,18 @@ https://localhost:5000/update_metric
138
138
 
139
139
  ### Submitting a Metric to the Flask API
140
140
  ```bash
141
- curl -k -X POST https://localhost:5000/update_metric \
141
+ curl -X POST http://localhost:5000/update_metric \
142
142
  -H "Content-Type: application/json" \
143
143
  -d '{
144
144
  "result": [
145
- { "label": "cpu_usage", "value": 42.5 }
145
+ {
146
+ "label": ["cpu", "core_1"],
147
+ "value": 42.5
148
+ }
146
149
  ],
147
- "labels": ["cpu"]
150
+ "labels": ["metric_type", "core"],
151
+ "main_label": "cpu_usage_metric"
148
152
  }'
149
-
150
153
  ```
151
154
 
152
155
  ### commands.yaml
@@ -10,9 +10,9 @@ flexmetric/metric_process/database_processing.py,sha256=hbVbzIdO21NF0F3nILJ4d1x8
10
10
  flexmetric/metric_process/expiring_queue.py,sha256=1oC0MjloitPiRo7yDgVarz81ETEQavKI_W-GFUvp5_Y,1920
11
11
  flexmetric/metric_process/process_commands.py,sha256=clGMQhLNcuJUO1gElpAS9Dyk0KU5w41DIguczjo7ceA,4089
12
12
  flexmetric/metric_process/prometheus_agent.py,sha256=rZ9pQrqA3J_-sJtl48qkFIHIUH01iert05u4SmGN4Yc,7714
13
- flexmetric/metric_process/views.py,sha256=vdL7PyZ8KRvEn6UM4HUtUZdCufzTL_JkkMEy0J2-4Ng,1939
14
- flexmetric-0.4.0.dist-info/METADATA,sha256=RQTETb4livHASNzKCDg6N1JOrrzl8skM1rrv2p9vk4g,10498
15
- flexmetric-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- flexmetric-0.4.0.dist-info/entry_points.txt,sha256=urVePn5EWr3JqNvkYP7OsB_h2_Bqvv-Wq1MJRBexm8A,79
17
- flexmetric-0.4.0.dist-info/top_level.txt,sha256=zBlrNwKhXUNhgu9RRZnXxYwYnmE-eocRe6wKSmQROA4,11
18
- flexmetric-0.4.0.dist-info/RECORD,,
13
+ flexmetric/metric_process/views.py,sha256=BY695dCpTkJRc1KLC9RNpFTieFdHeHvyqyefmHhMauE,3297
14
+ flexmetric-0.4.1.dist-info/METADATA,sha256=kHQheeo9qUgtJD6Zyb8O7q6eZR8RTCs7DJXHDJ8Yfrc,10570
15
+ flexmetric-0.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ flexmetric-0.4.1.dist-info/entry_points.txt,sha256=urVePn5EWr3JqNvkYP7OsB_h2_Bqvv-Wq1MJRBexm8A,79
17
+ flexmetric-0.4.1.dist-info/top_level.txt,sha256=zBlrNwKhXUNhgu9RRZnXxYwYnmE-eocRe6wKSmQROA4,11
18
+ flexmetric-0.4.1.dist-info/RECORD,,