influxdata / influxdata/influx-cli

`influx apply --json` outputs invalid JSON

Open
#75 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
75
Forks
22
PR merge metrics
No merged PRs in 30d

Description

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`:
```yaml
apiVersion: influxdata.com/v2alpha1
kind: Label
metadata:
name: foo-bar-ab9001
spec:
color: '#066fc5'
name: some_label
```
2. Run `influx apply -f example.yaml --force true --json`
3. 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`

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing `influx apply -f example.yaml --force true --json` with the minimal YAML template from the issue, then trace the CLI's JSON output path. Done means the command emits one parseable JSON document rather than concatenated documents, while preserving the reported apply information.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.