@@ -71,7 +71,11 @@ def get_driver_version() -> str:
7171 return snowflake .connector .__version__
7272
7373
74- def setup_schema (cursor : snowflake .connector .cursor .SnowflakeCursor , schema_name : str ):
74+ def setup_schema (
75+ cursor : snowflake .connector .cursor .SnowflakeCursor ,
76+ schema_name : str ,
77+ metric_name : str = "cloudprober_driver_python_create_schema" ,
78+ ):
7579 """
7680 Sets up the schema in Snowflake.
7781
@@ -84,19 +88,21 @@ def setup_schema(cursor: snowflake.connector.cursor.SnowflakeCursor, schema_name
8488 cursor .execute (f"USE SCHEMA { schema_name } " )
8589 if cursor .fetchone ():
8690 print (
87- f"cloudprober_driver_python_create_schema {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
91+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
8892 )
8993 return schema_name
9094 except Exception as e :
9195 logger .error (f"Error creating schema: { e } " )
9296 print (
93- f"cloudprober_driver_python_create_schema {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
97+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
9498 )
9599 sys .exit (1 )
96100
97101
98102def setup_database (
99- cursor : snowflake .connector .cursor .SnowflakeCursor , database_name : str
103+ cursor : snowflake .connector .cursor .SnowflakeCursor ,
104+ database_name : str ,
105+ metric_name : str = "cloudprober_driver_python_create_database" ,
100106):
101107 """
102108 Sets up the database in Snowflake.
@@ -110,19 +116,21 @@ def setup_database(
110116 cursor .execute (f"USE DATABASE { database_name } ;" )
111117 if cursor .fetchone ():
112118 print (
113- f"cloudprober_driver_python_create_database {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
119+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
114120 )
115121 return database_name
116122 except Exception as e :
117123 logger .error (f"Error creating database: { e } " )
118124 print (
119- f"cloudprober_driver_python_create_database {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
125+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
120126 )
121127 sys .exit (1 )
122128
123129
124130def setup_warehouse (
125- cursor : snowflake .connector .cursor .SnowflakeCursor , warehouse_name : str
131+ cursor : snowflake .connector .cursor .SnowflakeCursor ,
132+ warehouse_name : str ,
133+ metric_name : str = "cloudprober_driver_python_setup_warehouse" ,
126134):
127135 """
128136 Sets up the warehouse in Snowflake.
@@ -137,17 +145,20 @@ def setup_warehouse(
137145 )
138146 cursor .execute (f"USE WAREHOUSE { warehouse_name } ;" )
139147 print (
140- f"cloudprober_driver_python_setup_warehouse {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
148+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
141149 )
142150 except Exception as e :
143151 logger .error (f"Error setup warehouse: { e } " )
144152 print (
145- f"cloudprober_driver_python_setup_warehouse {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
153+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
146154 )
147155 sys .exit (1 )
148156
149157
150- def create_data_table (cursor : snowflake .connector .cursor .SnowflakeCursor ) -> str :
158+ def create_data_table (
159+ cursor : snowflake .connector .cursor .SnowflakeCursor ,
160+ metric_name : str = "cloudprober_driver_python_create_table" ,
161+ ) -> str :
151162 """
152163 Creates a data table in Snowflake with the specified schema.
153164
@@ -167,24 +178,27 @@ def create_data_table(cursor: snowflake.connector.cursor.SnowflakeCursor) -> str
167178 cursor .execute (create_table_query )
168179 if cursor .fetchone ():
169180 print (
170- f"cloudprober_driver_python_create_table {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
181+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
171182 )
172183 # cursor.execute(f"USE TABLE {table_name};")
173184 else :
174185 print (
175- f"cloudprober_driver_python_create_table {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
186+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
176187 )
177188 sys .exit (1 )
178189 except Exception as e :
179190 logger .error (f"Error creating table: { e } " )
180191 print (
181- f"cloudprober_driver_python_create_table {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
192+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
182193 )
183194 sys .exit (1 )
184195 return table_name
185196
186197
187- def create_data_stage (cursor : snowflake .connector .cursor .SnowflakeCursor ) -> str :
198+ def create_data_stage (
199+ cursor : snowflake .connector .cursor .SnowflakeCursor ,
200+ metric_name : str = "cloudprober_driver_python_create_stage" ,
201+ ) -> str :
188202 """
189203 Creates a stage in Snowflake for data upload.
190204
@@ -198,24 +212,27 @@ def create_data_stage(cursor: snowflake.connector.cursor.SnowflakeCursor) -> str
198212 cursor .execute (create_stage_query )
199213 if cursor .fetchone ():
200214 print (
201- f"cloudprober_driver_python_create_stage {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
215+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
202216 )
203217 else :
204218 print (
205- f"cloudprober_driver_python_create_stage {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
219+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
206220 )
207221 sys .exit (1 )
208222 return stage_name
209223 except Exception as e :
210224 print (
211- f"cloudprober_driver_python_create_stage {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
225+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
212226 )
213227 logger .error (f"Error creating stage: { e } " )
214228 sys .exit (1 )
215229
216230
217231def copy_into_table_from_stage (
218- table_name : str , stage_name : str , cur : snowflake .connector .cursor .SnowflakeCursor
232+ table_name : str ,
233+ stage_name : str ,
234+ cur : snowflake .connector .cursor .SnowflakeCursor ,
235+ metric_name : str = "cloudprober_driver_python_copy_data_from_stage_into_table" ,
219236):
220237 """
221238 Copies data from a stage into a specified table in Snowflake.
@@ -236,23 +253,26 @@ def copy_into_table_from_stage(
236253 # Check if the data was loaded successfully
237254 if cur .fetchall ()[0 ][1 ] == "LOADED" :
238255 print (
239- f"cloudprober_driver_python_copy_data_from_stage_into_table {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
256+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
240257 )
241258 else :
242259 print (
243- f"cloudprober_driver_python_copy_data_from_stage_into_table {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
260+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
244261 )
245262 sys .exit (1 )
246263 except Exception as e :
247264 logger .error (f"Error copying data from stage to table: { e } " )
248265 print (
249- f"cloudprober_driver_python_copy_data_from_stage_into_table {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
266+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
250267 )
251268 sys .exit (1 )
252269
253270
254271def put_file_to_stage (
255- file_name : str , stage_name : str , cur : snowflake .connector .cursor .SnowflakeCursor
272+ file_name : str ,
273+ stage_name : str ,
274+ cur : snowflake .connector .cursor .SnowflakeCursor ,
275+ metric_name : str = "cloudprober_driver_python_perform_put" ,
256276):
257277 """
258278 Uploads a file to a specified stage in Snowflake.
@@ -270,39 +290,42 @@ def put_file_to_stage(
270290
271291 if response [0 ][6 ] == "UPLOADED" :
272292 print (
273- f"cloudprober_driver_python_perform_put {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
293+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
274294 )
275295 else :
276296 print (
277- f"cloudprober_driver_python_perform_put {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
297+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
278298 )
279299 sys .exit (1 )
280300 except Exception as e :
281301 logger .error (f"Error uploading file to stage: { e } " )
282302 print (
283- f"cloudprober_driver_python_perform_put {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
303+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
284304 )
285305 sys .exit (1 )
286306
287307
288308def count_data_from_table (
289- table_name : str , num_records : int , cur : snowflake .connector .cursor .SnowflakeCursor
309+ table_name : str ,
310+ num_records : int ,
311+ cur : snowflake .connector .cursor .SnowflakeCursor ,
312+ metric_name : str = "cloudprober_driver_python_data_transferred_completely" ,
290313):
291314 try :
292315 count = cur .execute (f"SELECT COUNT(*) FROM { table_name } " ).fetchone ()[0 ]
293316 if count == num_records :
294317 print (
295- f"cloudprober_driver_python_data_transferred_completely {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
318+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
296319 )
297320 else :
298321 print (
299- f"cloudprober_driver_python_data_transferred_completely {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
322+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
300323 )
301324 sys .exit (1 )
302325 except Exception as e :
303326 logger .error (f"Error counting data from table: { e } " )
304327 print (
305- f"cloudprober_driver_python_data_transferred_completely {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
328+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
306329 )
307330 sys .exit (1 )
308331
@@ -313,6 +336,7 @@ def compare_fetched_data(
313336 cur : snowflake .connector .cursor .SnowflakeCursor ,
314337 repetitions : int = 10 ,
315338 fetch_limit : int = 100 ,
339+ metric_name : str = "cloudprober_driver_python_data_integrity" ,
316340):
317341 """
318342 Compares the data fetched from the table with the data in the CSV file.
@@ -337,21 +361,25 @@ def compare_fetched_data(
337361 for y in range (len (fetched_data [0 ])):
338362 if str (fetched_data [random_index ][y ]) != csv_data [random_index ][y ]:
339363 print (
340- f"cloudprober_driver_python_data_integrity {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
364+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
341365 )
342366 sys .exit (1 )
343367 print (
344- f"cloudprober_driver_python_data_integrity {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
368+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
345369 )
346370 except Exception as e :
347371 logger .error (f"Error comparing fetched data: { e } " )
348372 print (
349- f"cloudprober_driver_python_data_integrity {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
373+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
350374 )
351375 sys .exit (1 )
352376
353377
354- def execute_get_command (stage_name : str , conn : snowflake .connector .SnowflakeConnection ):
378+ def execute_get_command (
379+ stage_name : str ,
380+ conn : snowflake .connector .SnowflakeConnection ,
381+ metric_name : str = "cloudprober_driver_python_perform_get" ,
382+ ):
355383 """
356384 Downloads a file from a specified stage in Snowflake.
357385
@@ -369,19 +397,19 @@ def execute_get_command(stage_name: str, conn: snowflake.connector.SnowflakeConn
369397 downloaded_files = os .listdir (download_dir )
370398 if downloaded_files :
371399 print (
372- f"cloudprober_driver_python_perform_get {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
400+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 0"
373401 )
374402
375403 else :
376404 print (
377- f"cloudprober_driver_python_perform_get {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
405+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
378406 )
379407 sys .exit (1 )
380408
381409 except Exception as e :
382410 logger .error (f"Error downloading file from stage: { e } " )
383411 print (
384- f"cloudprober_driver_python_perform_get {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
412+ f"{ metric_name } {{python_version={ get_python_version ()} , driver_version={ get_driver_version ()} }} 1"
385413 )
386414 sys .exit (1 )
387415 finally :
0 commit comments