This repository has been archived by the owner on Jan 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Label_Microservice worker should use the new Model classes (#85)
* Most of the inference logic in the Worker class can be deleted and we can instead use the newly created Model classes. * Use an in cluster deployment service * Log the model and thresholds. * cli.py is a simple CLI to send pubsub requests * It is ended for development and debugging. * Create a utility to parse issue specs of the form {org}/{repo}#number * We need to initialize IssueLabelPredictor() inside the pubsub thread; otherwise we have threading issues when trying to access the model. * The universal model needs to apply appropriate thresholds to its predictions. * Worker no longer needs to apply thresholding of predictions because that is now handled by the individual model classes. * Add a method to worker apply_repo_config that handles repo specific behavior specified in the YAML file in the repo * Apply aliases to the labels * If the config specifies which labels to predict then filter out all other labels. * When commenting on issues about the predictions, the bot should reate a markdown table with the probabilities for the labels in the comment. * Remove test_worker.py; the test is no longer relevant after the refactor. There is a TODO in worker.py to create an appropriate unittest for the new code. * Change how the GitHub App Private Keys are handled. * The private key should be mounted as a secret and an environment variable should specify the path of the PEM key. * Stop storing the PEM key as an environment variable and then in python code writing it to a file. * Change the name of the environment variables to add the prefix "GITHUB_" to make it more explanatory. * Move some of the helper methods for creating GitHubApp out of github_util and into the GitHubApp class Related to: #70 combine universal and repo specific models.
- Loading branch information
1 parent
32f8f30
commit 32432bd
Showing
8 changed files
with
283 additions
and
323 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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,35 @@ | ||
import logging | ||
import pytest | ||
|
||
from code_intelligence import util | ||
|
||
def test_parse_issue_spec(): | ||
"""A unittest for parsing issues. """ | ||
|
||
test_cases = [ | ||
{ | ||
"issue": "kubeflow/tfjob#153", | ||
"expected": ("kubeflow", "tfjob", 153) | ||
}, | ||
{ | ||
"issue": "kubeflow/tfjob/tfjob", | ||
"expected": (None, None, None) | ||
} | ||
] | ||
|
||
for c in test_cases: | ||
owner, repo, number = util.parse_issue_spec(c["issue"]) | ||
assert owner == c["expected"][0] | ||
assert repo == c["expected"][1] | ||
assert number == c["expected"][2] | ||
|
||
if __name__ == "__main__": | ||
logging.basicConfig( | ||
level=logging.INFO, | ||
format=('%(levelname)s|%(asctime)s' | ||
'|%(pathname)s|%(lineno)d| %(message)s'), | ||
datefmt='%Y-%m-%dT%H:%M:%S', | ||
) | ||
logging.getLogger().setLevel(logging.INFO) | ||
|
||
pytest.main() |
This file contains 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,47 @@ | ||
"""A cli for interacting with the models. | ||
The CLI can be used to publish issues to perform inference on to pubsub | ||
to be picked up by the backends. | ||
""" | ||
import logging | ||
import fire | ||
from code_intelligence import util | ||
from google.cloud import pubsub | ||
|
||
DEFAULT_TOPIC = "projects/issue-label-bot-dev/topics/TEST_event_queue" | ||
class Cli: | ||
|
||
@staticmethod | ||
def label_issue(issue, pubsub_topic=DEFAULT_TOPIC): | ||
"""Label a specific issue. | ||
Args: | ||
issue: The issue in the form {owner}/{repo}#{issue} | ||
pubsub_topic: (Optional) the pubsub topic to publish to. This should | ||
be in the form projects/{project}/topics/{topic_name} | ||
""" | ||
publisher = pubsub.PublisherClient() | ||
repo_owner, repo_name, issue_num = util.parse_issue_spec(issue) | ||
|
||
if not repo_owner: | ||
raise ValueError(f"issue={issue} didn't match regex " | ||
f"{util.ISSUE_RE.pattern}") | ||
|
||
# all attributes being published to pubsub must be sent as text strings | ||
publisher.publish(pubsub_topic, | ||
b'New issue.', | ||
# TODO(jlewi): Does the backend depend on the client | ||
# providing the installation id | ||
installation_id="", | ||
repo_owner=repo_owner, | ||
repo_name=repo_name, | ||
issue_num=str(issue_num)) | ||
|
||
if __name__ == "__main__": | ||
logging.basicConfig(level=logging.INFO, | ||
format=('%(levelname)s|%(asctime)s' | ||
'|%(message)s|%(pathname)s|%(lineno)d|'), | ||
datefmt='%Y-%m-%dT%H:%M:%S', | ||
) | ||
|
||
fire.Fire(Cli) |
This file contains 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.