influx-cli icon indicating copy to clipboard operation
influx-cli copied to clipboard

`influx apply --json` outputs invalid JSON

Open philomory opened this issue 5 years ago • 0 comments

When running influx apply -f $FILENAME --force true --json, the output to stdout is not parseable as JSON

Steps to reproduce: List the minimal actions needed to reproduce the behavior.

  1. Create a minimal template, eg. example.yaml:
apiVersion: influxdata.com/v2alpha1
kind: Label
metadata:
    name: foo-bar-ab9001
spec:
    color: '#066fc5'
    name: some_label
  1. Run influx apply -f example.yaml --force true --json
  2. Observe that the output is not, strictly speaking, valid JSON

Specifically, the output is the concatenation of two bits of text that are each individually valid JSON documents, but, you cannot simply concatenate JSON documents and still have valid JSON; for example, {} is a valid JSON document, but {}{} is not.

Expected behavior: Using the --json flag results in output that can be parsed by a JSON parsing library

Actual behavior: You get output that isn't valid JSON such as the following:

{
        "buckets": [],
        "checks": [],
        "dashboards": [],
        "labels": [
                {
                        "id": 0,
                        "stateStatus": "new",
                        "templateMetaName": "foo-bar-ab9001",
                        "kind": "Label",
                        "new": {
                                "name": "some_label",
                                "color": "#066fc5",
                                "description": ""
                        },
                        "old": null
                }
        ],
        "labelMappings": [],
        "notificationEndpoints": [],
        "notificationRules": [],
        "tasks": [],
        "telegrafConfigs": [],
        "variables": []
}
{
        "stackID": "06c65a42a111b000",
        "Summary": {
                "buckets": [],
                "checks": [],
                "dashboards": [],
                "notificationEndpoints": [],
                "notificationRules": [],
                "labels": [
                        {
                                "kind": "Label",
                                "templateMetaName": "foo-bar-ab9001",
                                "envReferences": [],
                                "id": 488176851853881344,
                                "orgID": 346504372515078680,
                                "name": "some_label",
                                "properties": {
                                        "color": "#066fc5",
                                        "description": ""
                                }
                        }
                ],
                "labelMappings": [],
                "missingEnvRefs": [],
                "missingSecrets": [],
                "summaryTask": [],
                "telegrafConfigs": [],
                "variables": []
        }
}

Environment info: InfluxDB Cloud 2.0 CLI tools version: Influx CLI 2.0.3 (git: fe04d346df) build_date: 2020-12-15T01:00:16Z

philomory avatar Dec 16 '20 02:12 philomory