-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge in AWS Telemetry files from v1.3 branch to main
- Loading branch information
Showing
10 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
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,84 @@ | ||
apiVersion: batch/v1beta1 | ||
kind: CronJob | ||
metadata: | ||
name: aws-kubeflow-telemetry | ||
spec: | ||
schedule: "0 0 * * *" | ||
concurrencyPolicy: Forbid | ||
successfulJobsHistoryLimit: 0 | ||
failedJobsHistoryLimit: 0 | ||
jobTemplate: | ||
spec: | ||
ttlSecondsAfterFinished: 0 | ||
backoffLimit: 3 | ||
template: | ||
metadata: | ||
annotations: | ||
# istio sidecar is not neeeded since there is no inbound or outbound traffic from the service mesh | ||
sidecar.istio.io/inject: "false" | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- name: amazonlinux | ||
image: public.ecr.aws/amazonlinux/amazonlinux:2 | ||
command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
# Following code uses IMDS service. See: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html | ||
get_instance_id() { | ||
# use IMDSv2 if enabled else fallback to IMDSv1 | ||
local _token | ||
_token=$(curl -s --retry 3 --max-time 3 -X PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") | ||
if [[ -n ${_token+x} ]]; then | ||
IMDSV2_HEADER=(-H "X-aws-ec2-metadata-token: ${_token}") | ||
fi | ||
INSTANCE_ID=$(curl -s --retry 3 "${IMDSV2_HEADER[@]}" http://169.254.169.254/latest/meta-data/instance-id) | ||
local _instance_id_regex="^(i-\S{17})" | ||
if [[ -z ${INSTANCE_ID+x} || ! ${INSTANCE_ID} =~ ${_instance_id_regex} ]]; then | ||
exit 0 | ||
fi | ||
} | ||
get_region() { | ||
# regions where S3 buckets have been created | ||
local _valid_regions=( | ||
"us-east-1" | ||
"us-east-2" | ||
"us-west-1" | ||
"us-west-2" | ||
"af-south-1" | ||
"ap-east-1" | ||
"ap-southeast-1" | ||
"ap-southeast-2" | ||
"ap-southeast-3" | ||
"ap-south-1" | ||
"ap-northeast-1" | ||
"ap-northeast-2" | ||
"ap-northeast-3" | ||
"ca-central-1" | ||
"eu-central-1" | ||
"eu-north-1" | ||
"eu-west-1" | ||
"eu-west-2" | ||
"eu-west-3" | ||
"eu-south-1" | ||
"me-south-1" | ||
"sa-east-1" | ||
) | ||
REGION=$(curl -s --retry 3 "${IMDSV2_HEADER[@]}" http://169.254.169.254/latest/meta-data/placement/availability-zone | awk '{print substr($1, 1, length($1)-1)}') | ||
if [[ -z ${REGION+x} || ! ${_valid_regions[${REGION}]+x} ]]; then | ||
exit 0 | ||
fi | ||
} | ||
sleep $((1 + $RANDOM % 300)) | ||
get_instance_id | ||
get_region | ||
# send a GET request to S3 access point | ||
curl -s -o /dev/null "https://kubeflow-on-aws-usage-tracking-${REGION}.s3.${REGION}.amazonaws.com/instance-${INSTANCE_ID}.log?x-instance-id=${INSTANCE_ID}" |
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,78 @@ | ||
# Since CronJob operates on fix schedule, this job is in place for one off tracking at the time Kubeflow is deployed. | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: aws-kubelow-telemetry | ||
spec: | ||
ttlSecondsAfterFinished: 0 | ||
backoffLimit: 3 | ||
template: | ||
metadata: | ||
annotations: | ||
# istio sidecar is not neeeded since there is no inbound or outbound traffic from the service mesh | ||
sidecar.istio.io/inject: "false" | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- name: amazonlinux | ||
image: public.ecr.aws/amazonlinux/amazonlinux:2 | ||
command: | ||
- /bin/sh | ||
- -c | ||
- | | ||
# Following code uses IMDS service. See: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html | ||
get_instance_id() { | ||
# use IMDSv2 if enabled else fallback to IMDSv1 | ||
local _token | ||
_token=$(curl -s --retry 3 --max-time 3 -X PUT http://169.254.169.254/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") | ||
if [[ -n ${_token+x} ]]; then | ||
IMDSV2_HEADER=(-H "X-aws-ec2-metadata-token: ${_token}") | ||
fi | ||
INSTANCE_ID=$(curl -s --retry 3 "${IMDSV2_HEADER[@]}" http://169.254.169.254/latest/meta-data/instance-id) | ||
local _instance_id_regex="^(i-\S{17})" | ||
if [[ -z ${INSTANCE_ID+x} || ! ${INSTANCE_ID} =~ ${_instance_id_regex} ]]; then | ||
exit 0 | ||
fi | ||
} | ||
get_region() { | ||
# regions where S3 buckets have been created | ||
local _valid_regions=( | ||
"us-east-1" | ||
"us-east-2" | ||
"us-west-1" | ||
"us-west-2" | ||
"af-south-1" | ||
"ap-east-1" | ||
"ap-southeast-1" | ||
"ap-southeast-2" | ||
"ap-southeast-3" | ||
"ap-south-1" | ||
"ap-northeast-1" | ||
"ap-northeast-2" | ||
"ap-northeast-3" | ||
"ca-central-1" | ||
"eu-central-1" | ||
"eu-north-1" | ||
"eu-west-1" | ||
"eu-west-2" | ||
"eu-west-3" | ||
"eu-south-1" | ||
"me-south-1" | ||
"sa-east-1" | ||
) | ||
REGION=$(curl -s --retry 3 "${IMDSV2_HEADER[@]}" http://169.254.169.254/latest/meta-data/placement/availability-zone | awk '{print substr($1, 1, length($1)-1)}') | ||
if [[ -z ${REGION+x} || ! ${_valid_regions[${REGION}]+x} ]]; then | ||
exit 0 | ||
fi | ||
} | ||
get_instance_id | ||
get_region | ||
# send a GET request to S3 access point | ||
curl -s -o /dev/null "https://kubeflow-on-aws-usage-tracking-${REGION}.s3.${REGION}.amazonaws.com/instance-${INSTANCE_ID}.log?x-instance-id=${INSTANCE_ID}" |
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,8 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
namespace: kubeflow | ||
commonLabels: | ||
app: aws-telemetry | ||
resources: | ||
- cronjob.yaml | ||
- job.yaml |
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
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