Skip to content

Commit

Permalink
Setup New Relic deployment marker (#332)
Browse files Browse the repository at this point in the history
* Decrease polling time BuildBuddy client

* Setup New Relic deployment marker with testing
  • Loading branch information
mvgijssel authored Jun 7, 2023
1 parent e22d957 commit f574b87
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 5 deletions.
48 changes: 47 additions & 1 deletion provisioner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,60 @@ task(
task(
name = "deploy",
cmds = [
"export COMMIT_SHA=$(git rev-parse HEAD)",
cmd.shell(
cmd.executable(":deploy_mark"),
"$COMMIT_SHA",
),
cmd.executable(":deploy_provision"),
cmd.executable(":deploy_validate"),
],
cwd = "$BUILD_WORKSPACE_DIRECTORY",
env = {
"SETUP_ENV": "prod",
},
)

py_binary(
name = "deploy_mark_binary",
srcs = [
"deploy_mark.py",
],
main = "deploy_mark.py",
deps = [
requirement("requests"),
],
)

task(
name = "deploy_mark",
cmds = [
secrets({
"ENTITY_GUID": "provisioner-mark-new-relic-api-key.entity_guid",
"NEW_RELIC_API_KEY": "provisioner-mark-new-relic-api-key.password",
}),
cmd.shell(
cmd.executable(":deploy_mark_binary"),
"$CLI_ARGS",
),
],
env = {
"OP_BINARY": cmd.executable("//tools/onepassword:op"),
},
exec_properties = {
"include-secrets": "true",
},
deps = ["//tools/onepassword:lib"],
)

task_test(
name = "deploy_test",
size = "large",
cmds = [
cmd.shell(
cmd.executable(":deploy_mark"),
"test-commit-sha",
),
cmd.executable(":deploy_provision"),
cmd.shell(
cmd.executable(":deploy_validate"),
Expand All @@ -135,6 +180,7 @@ task_test(
],
env = {
"PYINFRA_RUN_ARGS": "--dry",
"SETUP_ENV": "test",
},
)

Expand Down Expand Up @@ -198,7 +244,7 @@ task(
name = "validate",
cmds = [
secrets({
"NEW_RELIC_API_KEY": "provisioner-validate-api-key.password",
"NEW_RELIC_API_KEY": "provisioner-validate-new-relic-api-key.password",
}),
cmd.python("""
import os
Expand Down
47 changes: 47 additions & 0 deletions provisioner/deploy_mark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests
import os
import sys

url = "https://api.eu.newrelic.com/graphql"
entity_guid = os.environ["ENTITY_GUID"]
_, commit_sha = sys.argv
new_relic_api_key = os.environ["NEW_RELIC_API_KEY"]
group_id = commit_sha

headers = {
"Content-Type": "application/json",
"API-Key": new_relic_api_key,
}

query = """
mutation {
changeTrackingCreateDeployment(deployment: {
entityGuid: "%s",
commit: "%s",
groupId: "%s",
deploymentType: ROLLING,
version: "0.1",
}) {
changelog
commit
deepLink
deploymentId
deploymentType
description
groupId
user
}
}
""" % (
entity_guid,
commit_sha,
group_id,
)

response = requests.post(url, json={"query": query}, headers=headers)

if response.ok:
print("Request was successful.")
else:
print(response.text)
response.raise_for_status()
6 changes: 5 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
"bazel-module": {
"enabled": true
},
"bazel": {
"fileMatch": ["(^|/)WORKSPACE\\.bzlmod$"]
},
"docker-compose": {
"fileMatch": ["(^|/)docker-compose\\.yml\\.j2$"]
}
},
"automergeSchedule": ["after 9am every weekday", "before 5pm every weekday"]
}
3 changes: 2 additions & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ sqlalchemy==2.0.15;
semver==2.13.0;
bazel-runfiles==0.22.0;
grpclib[protobuf]==0.4.4;
googleapis-common-protos==1.59.0;
googleapis-common-protos==1.59.0;
requests==2.31.0;
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,7 @@ requests==2.31.0 \
--hash=sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f \
--hash=sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1
# via
# -r requirements.in
# homeassistant
# opentelemetry-exporter-otlp-proto-http
# pulumi-kubernetes
Expand Down
3 changes: 1 addition & 2 deletions tools/onepassword/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ def get_item_path(path):

json_string = result.stdout.decode("utf-8")
raw_data = json.loads(json_string)

data = {}

for field in raw_data["fields"]:
data[field["id"]] = field.get("value", None)
data[field["label"]] = field.get("value", None)

return data[item_field]

0 comments on commit f574b87

Please sign in to comment.