gambol99 / go-marathon

A GO API library for working with Marathon
Apache License 2.0
199 stars 128 forks source link

lastTaskFailure is always nil #325

Closed zanes2016 closed 7 years ago

zanes2016 commented 7 years ago

The lastTaskFailure field does not seem to be parsed correctly; it is always nil.

Marathon Version: 1.4.7-1.0.657.ubuntu1404

Is anyone else experiencing this same issue?

Here's a the sample curl command that shows the lastTaskFailure:

curl -s localhost:80/v2/apps/test | python3 -m json.tool
{
    "app": {
        "acceptedResourceRoles": [
            "*"
        ],
        "args": null,
        "backoffFactor": 1.15,
        "backoffSeconds": 1,
        "cmd": "sleep 5; exit 1",
        "constraints": [],
        "container": null,
        "cpus": 1,
        "dependencies": [],
        "deployments": [],
        "disk": 0,
        "env": {},
        "executor": "",
        "fetch": [],
        "gpus": 0,
        "healthChecks": [],
        "id": "/test",
        "instances": 1,
        "ipAddress": null,
        "killSelection": "YOUNGEST_FIRST",
        "labels": {},
        "lastTaskFailure": {
            "appId": "/test",
            "host": "172.27.1.32",
            "message": "Command exited with status 1",
            "slaveId": "01b2caf4-2384-4e44-995a-46a0f12b4cfd-S0",
            "state": "TASK_FAILED",
            "taskId": "test.dd66db8f-9d66-11e7-9348-6acadaa9403a",
            "timestamp": "2017-09-19T18:18:03.658Z",
            "version": "2017-09-19T18:16:08.031Z"
        },
        "maxLaunchDelaySeconds": 3600,
        "mem": 128,
        "portDefinitions": [
            {
                "labels": {},
                "name": "default",
                "port": 10043,
                "protocol": "tcp"
            }
        ],
        "ports": [
            10043
        ],
        "readinessChecks": [],
        "requirePorts": false,
        "residency": null,
        "secrets": {},
        "storeUrls": [],
        "taskKillGracePeriodSeconds": null,
        "tasks": [],
        "tasksHealthy": 0,
        "tasksRunning": 0,
        "tasksStaged": 0,
        "tasksUnhealthy": 0,
        "unreachableStrategy": {
            "expungeAfterSeconds": 600,
            "inactiveAfterSeconds": 300
        },
        "upgradeStrategy": {
            "maximumOverCapacity": 1,
            "minimumHealthCapacity": 1
        },
        "uris": [],
        "user": null,
        "version": "2017-09-19T18:16:08.031Z",
        "versionInfo": {
            "lastConfigChangeAt": "2017-09-19T18:14:25.449Z",
            "lastScalingAt": "2017-09-19T18:16:08.031Z"
        }
    }
}

Here's a MarshalIndent output of the same App that is missing the lastTaskFailure:

{
   "id": "/test",
   "cmd": "sleep 5; exit 1",
   "constraints": [],
   "cpus": 1,
   "gpus": 0,
   "disk": 0,
   "executor": "",
   "healthChecks": [],
   "readinessChecks": [],
   "instances": 1,
   "mem": 128,
   "ports": [
      10043
   ],
   "portDefinitions": [
      {
         "port": 10043,
         "protocol": "tcp",
         "name": "default",
         "labels": {}
      }
   ],
   "requirePorts": false,
   "backoffSeconds": 1,
   "backoffFactor": 1.15,
   "maxLaunchDelaySeconds": 3600,
   "dependencies": [],
   "tasksRunning": 1,
   "upgradeStrategy": {
      "minimumHealthCapacity": 1,
      "maximumOverCapacity": 1
   },
   "unreachableStrategy": {
      "inactiveAfterSeconds": 300,
      "expungeAfterSeconds": 600
   },
   "killSelection": "YOUNGEST_FIRST",
   "uris": [],
   "version": "2017-09-19T18:16:08.031Z",
   "versionInfo": {
      "lastScalingAt": "2017-09-19T18:16:08.031Z",
      "lastConfigChangeAt": "2017-09-19T18:14:25.449Z"
   },
   "labels": {},
   "acceptedResourceRoles": [
      "*"
   ],
   "fetch": []
}

Here's a code snippet of what I have to print the above json string:

 // Create Marathon Client
    conf := gm.NewDefaultConfig()
    conf.URL = *config.SchedulerMasterUrl
    conf.EventsTransport = gm.EventsTransportSSE
    client, err := gm.NewClient(conf)
    if err != nil {
        return err
    }

    applications, err := client.Applications(nil)
    if err != nil {
        return err
    }

    for _, app := range applications.Apps {
        str, err := json.MarshalIndent(app, "", "   ")
        if err != nil {
            log.Println(err)
        }
        log.Printf("%s", str)
    }
zanes2016 commented 7 years ago

This is not an issue. This was a misunderstanding of the API.

client.Application("app-name") properly returns the LastTaskFailure field as supplied by the URI endpoint /v2/apps/app-name. Marathon URI endpoint /v2/apps does not return LastTaskFailure for each app; which is why it is empty in the client.Applications() call.