influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
29.05k stars 3.56k forks source link

POST checks api: panic happens if `time_since` is not sent #21798

Open russorat opened 3 years ago

russorat commented 3 years ago

discovered in: https://github.com/influxdata/influxdb/issues/21793

to repro, try to create a deadman check with the following request (filling in your own org, token, org id):

curl --location --request POST 'https://localhost:8086/api/v2/checks?org=InfluxData' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token mytoken' \
--data-raw '{
    "description": "something",
    "every": "1m",
    "labels": [],
    "level": "CRIT",
    "name": "something",
    "offset": "0s",
    "orgID": "38724d454ca19fd7",
    "query": {
        "builderConfig": {
            "buckets": [
                "telegraf"
            ],
            "functions": [],
            "tags": [
                {
                    "aggregateFunctionType": "filter",
                    "key": "_measurement",
                    "values": [
                        "go_info"
                    ]
                },
                {
                    "aggregateFunctionType": "filter",
                    "key": "_field",
                    "values": [
                        "gauge"
                    ]
                },
                {
                    "aggregateFunctionType": "filter",
                    "key": "host",
                    "values": []
                }
            ]
        },
        "editMode": "builder",
        "hidden": false,
        "name": "",
        "text": "buckets()"
    },
    "reportZero": false,
    "staleTime": "10m",
    "status": "active",
    "statusMessageTemplate": "Check: ${ r._check_name } is: ${ r._level }",
    "tags": [],
    "type": "deadman"
}'

results in:

{
    "code": "internal error",
    "message": "a panic has occurred: /api/v2/checks?org=InfluxData: runtime error: invalid memory address or nil pointer dereference"
}

making the same request but adding "timeSince": "90s" to the request succeeds:

curl --location --request POST 'https://localhost:8086/api/v2/checks?org=InfluxData' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token mytoken' \
--data-raw '{
    "description": "something",
    "every": "1m",
    "labels": [],
    "level": "CRIT",
    "name": "something",
    "offset": "0s",
    "orgID": "38724d454ca19fd7",
    "query": {
        "builderConfig": {
            "buckets": [
                "telegraf"
            ],
            "functions": [],
            "tags": [
                {
                    "aggregateFunctionType": "filter",
                    "key": "_measurement",
                    "values": [
                        "go_info"
                    ]
                },
                {
                    "aggregateFunctionType": "filter",
                    "key": "_field",
                    "values": [
                        "gauge"
                    ]
                },
                {
                    "aggregateFunctionType": "filter",
                    "key": "host",
                    "values": []
                }
            ]
        },
        "editMode": "builder",
        "hidden": false,
        "name": "",
        "text": "buckets()"
    },
    "reportZero": false,
    "staleTime": "10m",
    "status": "active",
    "statusMessageTemplate": "Check: ${ r._check_name } is: ${ r._level }",
    "tags": [],
    "type": "deadman",
    "timeSince": "90s"
}'
russorat commented 3 years ago

trying on influxdb cloud, it doesn't panic, but the following error is returned which might help track down the issue:

HTTP response body: {"code":"invalid","message":"Could not create task from check: missing field `values` at line 1 column 4495"}