1
+ ---
2
+ apiVersion : apps/v1
3
+ kind : Deployment
4
+ metadata :
5
+ name : model-pinger
6
+ labels :
7
+ app : model-pinger
8
+ spec :
9
+ replicas : 1
10
+ revisionHistoryLimit : 3
11
+ selector :
12
+ matchLabels :
13
+ app : model-pinger
14
+ strategy :
15
+ type : RollingUpdate
16
+ rollingUpdate :
17
+ maxSurge : 1
18
+ maxUnavailable : 100%
19
+ template :
20
+ metadata :
21
+ labels :
22
+ app : model-pinger
23
+ spec :
24
+ containers :
25
+ - name : pinger
26
+ image : quay.io/rlundber/sds-small:1.8
27
+ command :
28
+ - python
29
+ - -u
30
+ - /ping_model.py
31
+ env :
32
+ - name : MM_SERVING_HOST
33
+ value : modelmesh-serving:8008
34
+ - name : MM_MODEL_NAME
35
+ # value: fraud-4
36
+ value : fraud-latest
37
+ - name : SLEEP_TIME
38
+ value : " 5"
39
+ resources :
40
+ limits :
41
+ cpu : " 0.2"
42
+ memory : 256Mi
43
+ volumeMounts :
44
+ - name : pinger-config
45
+ subPath : ping_model.py
46
+ mountPath : /ping_model.py
47
+ volumes :
48
+ - name : pinger-config
49
+ configMap :
50
+ name : model-pinger
51
+
52
+ ---
53
+ apiVersion : v1
54
+ kind : ConfigMap
55
+ metadata :
56
+ name : model-pinger
57
+ data :
58
+ ping_model.py : |
59
+ import os
60
+ import time
61
+ from datetime import datetime
62
+ import random
63
+
64
+ # MM_SERVING_HOST = os.environ.get("MM_SERVING_HOST", "modelmesh-serving:8008")
65
+ # MM_MODEL_NAME = os.environ.get("MM_MODEL_NAME", "fraud-latest")
66
+
67
+ # # deployed_model_name = "fraud-latest"
68
+ # # rest_url = "http://modelmesh-serving:8008"
69
+ # deployed_model_name = MM_MODEL_NAME
70
+ # rest_url = f"http://{MM_SERVING_HOST}"
71
+ # infer_url = f"{rest_url}/v2/models/{deployed_model_name}/infer"
72
+ # print(infer_url)
73
+
74
+ # import requests
75
+
76
+ # def rest_request(data):
77
+ # json_data = {
78
+ # "inputs": [
79
+ # {
80
+ # "name": "dense_input",
81
+ # "shape": [1, 5],
82
+ # "datatype": "FP32",
83
+ # "data": data
84
+ # }
85
+ # ]
86
+ # }
87
+
88
+ # response = requests.post(infer_url, json=json_data)
89
+ # response_dict = response.json()
90
+ # return response_dict['outputs'][0]['data']
91
+
92
+
93
+ # MM_SERVING_HOST = os.environ.get("MM_SERVING_HOST", "modelmesh-serving:8033")
94
+ # MM_MODEL_NAME = os.environ.get("MM_MODEL_NAME", "ansible-model-pinger")
95
+
96
+ # SLEEP_TIME = os.environ.get("SLEEP_TIME", "3")
97
+ # SLEEP_TIME = int(SLEEP_TIME)
98
+
99
+
100
+ # while True:
101
+ # now = datetime.now()
102
+ # time_string = now.strftime("%Y-%m-%d %H:%M:%S")
103
+
104
+ # print("--------------------------------------")
105
+ # print("Sending Request at",time_string)
106
+
107
+ # start = time.time()
108
+ # try:
109
+ # random_dist = round(random.uniform(0, 50), 2)
110
+ # data = [random_dist, 1.9459399775518593, 1.0, 0.0, 0.0]
111
+ # print("Data sent to model ("+deployed_model_name+"):")
112
+ # print(data)
113
+
114
+ # # Start the timer
115
+ # start_time = time.time()
116
+
117
+ # prediction = rest_request(data)
118
+
119
+ # # End the timer
120
+ # end_time = time.time()
121
+
122
+ # # Calculate the elapsed time in milliseconds
123
+ # response_time_ms = (end_time - start_time) * 1000
124
+
125
+ # # prediction
126
+ # print("Likelyhood of fraud")
127
+ # print(str(prediction[0]*100)+"%")
128
+
129
+ # print("Prediction took ", response_time_ms, "milliseconds")
130
+
131
+ # except Exception as e:
132
+ # print(f"Errored after {time.time() - start}s: {e}")
133
+
134
+ # time.sleep(SLEEP_TIME)
0 commit comments