Skip to content

Commit

Permalink
SK-678 add metrices in python-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
skyflow-bharti committed May 17, 2023
1 parent 442a7d7 commit 6add72a
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
git config user.name ${{ github.actor }}
git config user.email ${{ github.actor }}@users.noreply.github.com
git add setup.py
git add version.py
git commit -m "[AUTOMATED] Public Release - ${{ steps.previoustag.outputs.tag }}"
git push origin
Expand Down
3 changes: 3 additions & 0 deletions ci-scripts/bump_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ then
echo "Bumping package version to $1"

sed -E "s/current_version = .+/current_version = \'$SEMVER\'/g" setup.py > tempfile && cat tempfile > setup.py && rm -f tempfile
sed -E "s/SDK_VERSION = .+/SDK_VERSION = \'$SEMVER\'/g" version.py > tempfile && cat tempfile > version.py && rm -f tempfile

echo --------------------------
echo "Done, Package now at $1"

else
echo "Bumping package version to $1-dev.$2"

sed -E "s/current_version = .+/current_version = \'$SEMVER-dev.$2\'/g" setup.py > tempfile && cat tempfile > setup.py && rm -f tempfile
sed -E "s/SDK_VERSION = .+/SDK_VERSION = \'$SEMVER-dev.$2\'/g" version.py > tempfile && cat tempfile > version.py && rm -f tempfile

echo --------------------------
echo "Done, Package now at $1-dev.$2"
Expand Down
14 changes: 14 additions & 0 deletions skyflow/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import urllib.parse
import logging
from enum import Enum
import platform
import sys
from version import SDK_VERSION

skyflowLog = logging.getLogger('skyflow')
skyflowLog.setLevel(logging.ERROR)
Expand Down Expand Up @@ -127,3 +130,14 @@ def render_key(parents):
outStr += s % str(x)
depth += 1
return outStr

def getMetrics():
''' fetch metrics
'''
details_dic = {
'sdk_name_version': "skyflow-python@" + SDK_VERSION,
'sdk_client_device_model': platform.node(),
'sdk_client_os_details': sys.platform,
'sdk_runtime_details': sys.version,
}
return details_dic
6 changes: 4 additions & 2 deletions skyflow/vault/_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'''
Copyright (c) 2022 Skyflow, Inc.
'''
import json
import types
import requests
from ._insert import getInsertRequestBody, processResponse, convertResponse
Expand All @@ -13,7 +14,7 @@
from ._get import sendGetRequests
import asyncio
from skyflow.errors._skyflow_errors import SkyflowError, SkyflowErrorCodes, SkyflowErrorMessages
from skyflow._utils import log_info, InfoMessages, InterfaceName
from skyflow._utils import log_info, InfoMessages, InterfaceName, getMetrics
from ._token import tokenProviderWrapper


Expand Down Expand Up @@ -52,7 +53,8 @@ def insert(self, records: dict, options: InsertOptions = InsertOptions()):
self.storedToken = tokenProviderWrapper(
self.storedToken, self.tokenProvider, interface)
headers = {
"Authorization": "Bearer " + self.storedToken
"Authorization": "Bearer " + self.storedToken,
"sky-metadata": json.dumps(getMetrics())
}

response = requests.post(requestURL, data=jsonBody, headers=headers)
Expand Down
6 changes: 4 additions & 2 deletions skyflow/vault/_detokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import asyncio
from aiohttp import ClientSession, request
import json
from skyflow._utils import InterfaceName
from skyflow._utils import InterfaceName, getMetrics

interface = InterfaceName.DETOKENIZE.value

Expand Down Expand Up @@ -48,7 +48,9 @@ async def sendDetokenizeRequests(data, url, token):
async with ClientSession() as session:
for record in validatedRecords:
headers = {
"Authorization": "Bearer " + token
"Authorization": "Bearer " + token,
"sky-metadata": json.dumps(getMetrics())

}
task = asyncio.ensure_future(post(url, record, headers, session))
tasks.append(task)
Expand Down
6 changes: 4 additions & 2 deletions skyflow/vault/_get.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'''
Copyright (c) 2022 Skyflow, Inc.
'''
import json
from skyflow.errors._skyflow_errors import SkyflowError, SkyflowErrorCodes, SkyflowErrorMessages
import asyncio
from aiohttp import ClientSession
from ._config import RedactionType
from skyflow._utils import InterfaceName
from skyflow._utils import InterfaceName, getMetrics
from ._get_by_id import get

interface = InterfaceName.GET.value
Expand Down Expand Up @@ -83,7 +84,8 @@ async def sendGetRequests(data, url, token):
async with ClientSession() as session:
for record in validatedRecords:
headers = {
"Authorization": "Bearer " + token
"Authorization": "Bearer " + token,
"sky-metadata": json.dumps(getMetrics())
}
params = {"redaction": redaction}
if ids is not None:
Expand Down
5 changes: 3 additions & 2 deletions skyflow/vault/_get_by_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from aiohttp import ClientSession
import json
from ._config import RedactionType
from skyflow._utils import InterfaceName
from skyflow._utils import InterfaceName, getMetrics

interface = InterfaceName.GET_BY_ID.value

Expand Down Expand Up @@ -66,7 +66,8 @@ async def sendGetByIdRequests(data, url, token):
async with ClientSession() as session:
for record in validatedRecords:
headers = {
"Authorization": "Bearer " + token
"Authorization": "Bearer " + token,
"sky-metadata": json.dumps(getMetrics())
}
params = {"skyflow_ids": record[0], "redaction": record[2]}
task = asyncio.ensure_future(
Expand Down
5 changes: 3 additions & 2 deletions skyflow/vault/_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import asyncio
from skyflow.errors._skyflow_errors import SkyflowError, SkyflowErrorCodes, SkyflowErrorMessages
from ._insert import getTableAndFields
from skyflow._utils import InterfaceName
from skyflow._utils import InterfaceName, getMetrics
from aiohttp import ClientSession
from ._config import UpdateOptions

Expand Down Expand Up @@ -40,7 +40,8 @@ async def sendUpdateRequests(data,options: UpdateOptions,url,token):
}
reqBody = json.dumps(reqBody)
headers = {
"Authorization": "Bearer " + token
"Authorization": "Bearer " + token,
"sky-metadata": json.dumps(getMetrics())
}
task = asyncio.ensure_future(put(recordUrl, reqBody, headers, session))
tasks.append(task)
Expand Down
16 changes: 14 additions & 2 deletions tests/vault/test_url_encoder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'''
Copyright (c) 2022 Skyflow, Inc.
'''
import platform
import sys
import unittest
from skyflow._utils import http_build_query

from skyflow._utils import http_build_query, getMetrics
from version import SDK_VERSION

class TestUrlEncoder(unittest.TestCase):
def setUp(self) -> None:
Expand Down Expand Up @@ -50,3 +52,13 @@ def test_encoder_array(self):

self.assertEqual(
http_data, "key=value&nested%5Barray%5D%5B0%5D=one&nested%5Barray%5D%5B1%5D=two&nested%5Bkey%5D=value")

def test_get_metrics(self):
expected = {
'sdk_name_version': "skyflow-python@" + SDK_VERSION,
'sdk_client_device_model': platform.node(),
'sdk_client_os_details': sys.platform,
'sdk_runtime_details': sys.version,
}
actual = getMetrics()
self.assertEqual(actual, expected)
1 change: 1 addition & 0 deletions version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SDK_VERSION = '1.8.1'

0 comments on commit 6add72a

Please sign in to comment.