-
Notifications
You must be signed in to change notification settings - Fork 77
feat: Knative deployment support #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
octonawish-akcodes
wants to merge
11
commits into
spcl:master
Choose a base branch
from
octonawish-akcodes:knative
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5f13fc7
feat: Knative deployment support
octonawish-akcodes f74a2df
Added knative preparation script
octonawish-akcodes 8779f50
added wrappers and updated knative functions
octonawish-akcodes 088ca51
added cached_function
octonawish-akcodes 574cbd7
fixed knative script
octonawish-akcodes ef63c4b
minor fixes
octonawish-akcodes b803caf
updated microbenchmarks and knative integration
octonawish-akcodes 16f1d07
Added docs and regression support
octonawish-akcodes 7b50418
added support for s2i image building instead of pack
octonawish-akcodes c38ded8
fix
octonawish-akcodes 07d38ed
fix knative update functions & updated deployment instructions
octonawish-akcodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { CloudEvent, HTTP } = require('cloudevents'); | ||
const handler = require('./function').handler; | ||
|
||
async function handle(context, event) { | ||
const startTime = new Date(); | ||
|
||
try { | ||
// Ensure event data is parsed correctly | ||
const eventData = event ? event : context.body; | ||
context.log.info(`Received event: ${JSON.stringify(eventData)}`); | ||
|
||
// Call the handler function with the event data | ||
const result = await handler(eventData); | ||
const endTime = new Date(); | ||
|
||
context.log.info(`Function result: ${JSON.stringify(result)}`); | ||
const resultTime = (endTime - startTime) / 1000; // Time in seconds | ||
|
||
// Create a response | ||
const response = { | ||
begin: startTime.toISOString(), | ||
end: endTime.toISOString(), | ||
results_time: resultTime, | ||
result: result | ||
}; | ||
|
||
// Return the response | ||
return { | ||
data: response, | ||
headers: { 'Content-Type': 'application/json' }, | ||
statusCode: 200 | ||
}; | ||
} catch (error) { | ||
const endTime = new Date(); | ||
const resultTime = (endTime - startTime) / 1000; // Time in seconds | ||
|
||
context.log.error(`Error - invocation failed! Reason: ${error.message}`); | ||
const response = { | ||
begin: startTime.toISOString(), | ||
end: endTime.toISOString(), | ||
results_time: resultTime, | ||
result: `Error - invocation failed! Reason: ${error.message}` | ||
}; | ||
|
||
// Return the error response | ||
return { | ||
data: response, | ||
headers: { 'Content-Type': 'application/json' }, | ||
statusCode: 500 | ||
}; | ||
} | ||
} | ||
|
||
module.exports = handle; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
const minio = require('minio'), | ||
path = require('path'), | ||
uuid = require('uuid'), | ||
util = require('util'), | ||
stream = require('stream'), | ||
fs = require('fs'); | ||
|
||
class minio_storage { | ||
|
||
constructor() { | ||
let address = process.env.MINIO_STORAGE_CONNECTION_URL; | ||
let access_key = process.env.MINIO_STORAGE_ACCESS_KEY; | ||
let secret_key = process.env.MINIO_STORAGE_SECRET_KEY; | ||
|
||
this.client = new minio.Client( | ||
{ | ||
endPoint: address.split(':')[0], | ||
port: parseInt(address.split(':')[1], 10), | ||
accessKey: access_key, | ||
secretKey: secret_key, | ||
useSSL: false | ||
} | ||
); | ||
} | ||
|
||
unique_name(file) { | ||
let name = path.parse(file); | ||
let uuid_name = uuid.v4().split('-')[0]; | ||
return path.join(name.dir, util.format('%s.%s%s', name.name, uuid_name, name.ext)); | ||
} | ||
|
||
upload(bucket, file, filepath) { | ||
let uniqueName = this.unique_name(file); | ||
return [uniqueName, this.client.fPutObject(bucket, uniqueName, filepath)]; | ||
}; | ||
|
||
download(bucket, file, filepath) { | ||
return this.client.fGetObject(bucket, file, filepath); | ||
}; | ||
|
||
uploadStream(bucket, file) { | ||
var write_stream = new stream.PassThrough(); | ||
let uniqueName = this.unique_name(file); | ||
let promise = this.client.putObject(bucket, uniqueName, write_stream, write_stream.size); | ||
return [write_stream, promise, uniqueName]; | ||
}; | ||
|
||
downloadStream(bucket, file) { | ||
var read_stream = new stream.PassThrough(); | ||
return this.client.getObject(bucket, file); | ||
}; | ||
|
||
static get_instance() { | ||
if(!this.instance) { | ||
this.instance = new storage(); | ||
} | ||
return this.instance; | ||
} | ||
|
||
|
||
}; | ||
exports.storage = minio_storage; |
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import logging | ||
import datetime | ||
from flask import jsonify | ||
from parliament import Context | ||
from function import handler | ||
|
||
def main(context: Context): | ||
logging.getLogger().setLevel(logging.INFO) | ||
begin = datetime.datetime.now() # Initialize begin outside the try block | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
try: | ||
# Extract JSON data from the request | ||
event = context.request.json | ||
|
||
# Update the timestamp after extracting JSON data | ||
begin = datetime.datetime.now() | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Pass the extracted JSON data to the handler function | ||
ret = handler(event) | ||
end = datetime.datetime.now() | ||
logging.info(f"Function result: {ret}") | ||
results_time = (end - begin) / datetime.timedelta(microseconds=1) | ||
|
||
response = { | ||
"begin": begin.strftime("%s.%f"), | ||
"end": end.strftime("%s.%f"), | ||
"results_time": results_time, | ||
"result": ret, | ||
} | ||
|
||
return jsonify(response), 200 | ||
|
||
except Exception as e: | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end = datetime.datetime.now() | ||
results_time = (end - begin) / datetime.timedelta(microseconds=1) | ||
logging.error(f"Error - invocation failed! Reason: {e}") | ||
response = { | ||
"begin": begin.strftime("%s.%f"), | ||
"end": end.strftime("%s.%f"), | ||
"results_time": results_time, | ||
"result": f"Error - invocation failed! Reason: {e}", | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return jsonify(response), 500 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import os | ||
import uuid | ||
import json | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import minio | ||
import logging | ||
|
||
|
||
class storage: | ||
instance = None | ||
client = None | ||
|
||
def __init__(self): | ||
try: | ||
""" | ||
Minio does not allow another way of configuring timeout for connection. | ||
The rest of configuration is copied from source code of Minio. | ||
""" | ||
import urllib3 | ||
from datetime import timedelta | ||
|
||
timeout = timedelta(seconds=1).seconds | ||
|
||
mgr = urllib3.PoolManager( | ||
timeout=urllib3.util.Timeout(connect=timeout, read=timeout), | ||
maxsize=10, | ||
retries=urllib3.Retry( | ||
total=5, backoff_factor=0.2, status_forcelist=[500, 502, 503, 504] | ||
) | ||
) | ||
self.client = minio.Minio( | ||
os.getenv("MINIO_STORAGE_CONNECTION_URL"), | ||
access_key=os.getenv("MINIO_STORAGE_ACCESS_KEY"), | ||
secret_key=os.getenv("MINIO_STORAGE_SECRET_KEY"), | ||
secure=False, | ||
http_client=mgr | ||
) | ||
except Exception as e: | ||
logging.info(e) | ||
raise e | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@staticmethod | ||
def unique_name(name): | ||
name, extension = os.path.splitext(name) | ||
return '{name}.{random}{extension}'.format( | ||
name=name, | ||
extension=extension, | ||
random=str(uuid.uuid4()).split('-')[0] | ||
) | ||
|
||
|
||
def upload(self, bucket, file, filepath): | ||
key_name = storage.unique_name(file) | ||
self.client.fput_object(bucket, key_name, filepath) | ||
return key_name | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def download(self, bucket, file, filepath): | ||
self.client.fget_object(bucket, file, filepath) | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def download_directory(self, bucket, prefix, path): | ||
objects = self.client.list_objects(bucket, prefix, recursive=True) | ||
for obj in objects: | ||
file_name = obj.object_name | ||
self.download(bucket, file_name, os.path.join(path, file_name)) | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def upload_stream(self, bucket, file, bytes_data): | ||
key_name = storage.unique_name(file) | ||
self.client.put_object( | ||
bucket, key_name, bytes_data, bytes_data.getbuffer().nbytes | ||
) | ||
return key_name | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def download_stream(self, bucket, file): | ||
data = self.client.get_object(bucket, file) | ||
return data.read() | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@staticmethod | ||
def get_instance(): | ||
if storage.instance is None: | ||
storage.instance = storage() | ||
return storage.instance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parliament-functions==0.1.0 | ||
octonawish-akcodes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
flask |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.