view the json piped in metric and evaluate.py #173
Replies: 2 comments 4 replies
-
Hi, To see the values piped to your script you can use the For example: evaluate:
type: "shell"
timeout: 2500
shell:
entrypoint: "python"
logStderr: true
command:
- "/evaluate.py"
metric:
type: "shell"
timeout: 2500
shell:
entrypoint: "python"
logStderr: true
command:
- "/metric.py"
runMode: "per-resource" This will log out anything that is written to standard error of the def main():
# Parse spec into a dict
stdin = sys.stdin.read()
spec = json.loads(stdin)
sys.stderr.write(stdin)
metric(spec)
... Then you should be able to see something like this in the logs:
(You can feed this into something like jq to get it pretty printed) {
"resource": {
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"annotations": {
"deployment.kubernetes.io/revision": "1",
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"labels\":{\"numPods\":\"3\"},\"name\":\"hello-kubernetes\",\"namespace\":\"default\"},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"app\":\"hello-kubernetes\"}},\"template\":{\"metadata\":{\"labels\":{\"app\":\"hello-kubernetes\"}},\"spec\":{\"containers\":[{\"image\":\"paulbouwer/hello-kubernetes:1.5\",\"name\":\"hello-kubernetes\",\"ports\":[{\"containerPort\":8080}]}]}}}}\n"
},
"creationTimestamp": "2022-07-06T21:51:55Z",
"generation": 2,
"labels": {
"numPods": "3"
},
"managedFields": [
{
"apiVersion": "apps/v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:spec": {
"f:replicas": {}
}
},
"manager": "custom-pod-autoscaler",
"operation": "Update",
"subresource": "scale"
},
{
"apiVersion": "apps/v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:annotations": {
".": {},
"f:kubectl.kubernetes.io/last-applied-configuration": {}
},
"f:labels": {
".": {},
"f:numPods": {}
}
},
"f:spec": {
"f:progressDeadlineSeconds": {},
"f:revisionHistoryLimit": {},
"f:selector": {},
"f:strategy": {
"f:rollingUpdate": {
".": {},
"f:maxSurge": {},
"f:maxUnavailable": {}
},
"f:type": {}
},
"f:template": {
"f:metadata": {
"f:labels": {
".": {},
"f:app": {}
}
},
"f:spec": {
"f:containers": {
"k:{\"name\":\"hello-kubernetes\"}": {
".": {},
"f:image": {},
"f:imagePullPolicy": {},
"f:name": {},
"f:ports": {
".": {},
"k:{\"containerPort\":8080,\"protocol\":\"TCP\"}": {
".": {},
"f:containerPort": {},
"f:protocol": {}
}
},
"f:resources": {},
"f:terminationMessagePath": {},
"f:terminationMessagePolicy": {}
}
},
"f:dnsPolicy": {},
"f:restartPolicy": {},
"f:schedulerName": {},
"f:securityContext": {},
"f:terminationGracePeriodSeconds": {}
}
}
}
},
"manager": "kubectl-client-side-apply",
"operation": "Update",
"time": "2022-07-06T21:51:55Z"
},
{
"apiVersion": "apps/v1",
"fieldsType": "FieldsV1",
"fieldsV1": {
"f:metadata": {
"f:annotations": {
"f:deployment.kubernetes.io/revision": {}
}
},
"f:status": {
"f:availableReplicas": {},
"f:conditions": {
".": {},
"k:{\"type\":\"Available\"}": {
".": {},
"f:lastTransitionTime": {},
"f:lastUpdateTime": {},
"f:message": {},
"f:reason": {},
"f:status": {},
"f:type": {}
},
"k:{\"type\":\"Progressing\"}": {
".": {},
"f:lastTransitionTime": {},
"f:lastUpdateTime": {},
"f:message": {},
"f:reason": {},
"f:status": {},
"f:type": {}
}
},
"f:observedGeneration": {},
"f:readyReplicas": {},
"f:replicas": {},
"f:updatedReplicas": {}
}
},
"manager": "k3s",
"operation": "Update",
"subresource": "status",
"time": "2022-07-06T21:52:15Z"
}
],
"name": "hello-kubernetes",
"namespace": "default",
"resourceVersion": "897",
"uid": "887aa97a-ed42-47ba-8703-67094a96d03a"
},
"spec": {
"progressDeadlineSeconds": 600,
"replicas": 6,
"revisionHistoryLimit": 10,
"selector": {
"matchLabels": {
"app": "hello-kubernetes"
}
},
"strategy": {
"rollingUpdate": {
"maxSurge": "25%",
"maxUnavailable": "25%"
},
"type": "RollingUpdate"
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"app": "hello-kubernetes"
}
},
"spec": {
"containers": [
{
"image": "paulbouwer/hello-kubernetes:1.5",
"imagePullPolicy": "IfNotPresent",
"name": "hello-kubernetes",
"ports": [
{
"containerPort": 8080,
"protocol": "TCP"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File"
}
],
"dnsPolicy": "ClusterFirst",
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"terminationGracePeriodSeconds": 30
}
}
},
"status": {
"availableReplicas": 6,
"conditions": [
{
"lastTransitionTime": "2022-07-06T21:51:55Z",
"lastUpdateTime": "2022-07-06T21:52:03Z",
"message": "ReplicaSet \"hello-kubernetes-ffd764cf9\" has successfully progressed.",
"reason": "NewReplicaSetAvailable",
"status": "True",
"type": "Progressing"
},
{
"lastTransitionTime": "2022-07-06T21:52:14Z",
"lastUpdateTime": "2022-07-06T21:52:14Z",
"message": "Deployment has minimum availability.",
"reason": "MinimumReplicasAvailable",
"status": "True",
"type": "Available"
}
],
"observedGeneration": 2,
"readyReplicas": 6,
"replicas": 6,
"updatedReplicas": 6
}
},
"runType": "scaler"
} Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
@jthomperoo I am also trying the getting started example. I set up I am using kind on Windows10, don't know if this will affect how things works. |
Beta Was this translation helpful? Give feedback.
-
Can you please tell me how to view the json piped into the metric.py script?
In example, I can see an example json piped, but I want to see the json piped into my CPA. Please help me in this.
Beta Was this translation helpful? Give feedback.
All reactions