Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consul kv import @a-file.json change behavior since 1.10.0 #10906

Closed
rocwenlinux opened this issue Aug 24, 2021 · 4 comments
Closed

consul kv import @a-file.json change behavior since 1.10.0 #10906

rocwenlinux opened this issue Aug 24, 2021 · 4 comments
Labels
theme/kv Issues related to the key value store type/bug Feature does not function as expected

Comments

@rocwenlinux
Copy link

Overview of the Issue

consul kv import @a-file.json change behavior since 1.10.0. The 1.9.8 and older versions treat "service/importtest/" (with slash at the end) as a key, but 1.10.x treat "service/importtest/" as "service/importtest", the tail slash is missing.

Reproduction Steps

Steps to reproduce this issue, eg:

  1. prepare a json file for importing, named as test.json.
[
	{
		"key": "service/importtest/",
		"flags": 0,
		"value": "MjAyMC4wMi4xNCAyMDo1Njo1Mw=="
	}
]
  1. Run consul kv import @test.json
  2. output
eric$ ~/Downloads/consul10.0 kv import @test.json
Imported: service/importtest
eric$ consul kv delete -recurse service/importtest
Success! Deleted keys with prefix: service/importtest
eric$ ~/Downloads/consul198 kv import @test.json
Imported: service/importtest/

Consul info for both Client and Server

Operating system and Environment details

consul cluster running consul 1.9.5, Ubuntu server
consul cli running in MacOS 11.5.2, intel

@jkirschner-hashicorp jkirschner-hashicorp added the type/bug Feature does not function as expected label Aug 30, 2021
@jkirschner-hashicorp jkirschner-hashicorp added the theme/kv Issues related to the key value store label Sep 28, 2021
blake added a commit that referenced this issue Dec 18, 2021
Correctly import keys names that end in a trailing slash.

Fixes #10906
@shantanugadgil
Copy link
Contributor

shantanugadgil commented Jan 7, 2022

@blake

I think there is a possible bug in the consul kv export as well, I checked with version 1.11.1.

The export of a recursive "folder" produces an entry with the trailing slash, like so:

consul kv export toplevel
[
        {
                "key": "toplevel/",
                "flags": 0,
                "value": ""
        },
        {
                "key": "toplevel/alpha",
                "flags": 0,
                "value": "c29tZXRoaW5nCg=="
        },
        {
                "key": "toplevel/bravo",
                "flags": 0,
                "value": "c29tZXRoaW5nCg=="
        }
...
]

For my case, the "key": "toplevel/", need not exist in the output at all, as it is NOT there as a separate key.

@blake
Copy link
Member

blake commented Jan 12, 2022

Hi @shantanugadgil,

I'm not able to reproduce the behavior you described with Consul 1.9.13, 1.10.6, or 1.11.1, unless I explicitly create the foo/ key. For example:

$  consul kv export foo/
[]

$ consul kv put foo/a aaa
consul kv put foo/b bbb
consul kv put foo/c ccc
Success! Data written to: foo/a
Success! Data written to: foo/b
Success! Data written to: foo/c

$ consul kv export foo/
[
        {
                "key": "foo/a",
                "flags": 0,
                "value": "YWFh"
        },
        {
                "key": "foo/b",
                "flags": 0,
                "value": "YmJi"
        },
        {
                "key": "foo/c",
                "flags": 0,
                "value": "Y2Nj"
        }
]

$ consul kv get -detailed foo/
Error! No key exists at: foo/

$ consul kv put foo/
Success! Data written to: foo/

$ consul kv get -detailed foo/
CreateIndex      23075398
Flags            0
Key              foo/
LockIndex        0
ModifyIndex      23075398
Session          -
Value

$ consul kv export foo/
[
        {
                "key": "foo/",
                "flags": 0,
                "value": ""
        },
        {
                "key": "foo/a",
                "flags": 0,
                "value": "YWFh"
        },
        {
                "key": "foo/b",
                "flags": 0,
                "value": "YmJi"
        },
        {
                "key": "foo/c",
                "flags": 0,
                "value": "Y2Nj"
        }
]

Can you verify that your top-level key was not manually created through some other means? If it is present and you don't need it, you can safely remove it from the KV store without affecting the ability to retrieve the other keys from the CLI or UI.

@shantanugadgil
Copy link
Contributor

shantanugadgil commented Jan 12, 2022

@blake this indeed seems to be the case; when the toplevel/ has been created separately, the weirdness happens.

I tried to reproduce the issue using the webui, and this gets all the more confusing as it violates WYSIWYG.

I feel there is more buggy behavior that easily visible.

Steps to repro via webui:
Consul version: 1.11.1

  1. in the webui, go to Key/Value
  2. create key named toplevel/ (with trailing slash)
  3. click toplevel "folder"
  4. click the blue Create button.
  5. I expect to see the combined boxes of Key or folder and Value, I see only the Value box. 😮
  6. Never mind, go back to Key/Value root, and create a key named toplevel/alpha with value aaa
  7. This gets created correctly (what I was actually trying to do in step 6 and 7)

I feel, seeing only the Value box in step 5 is a bug!

Also, if I do fill in some data when I see the Value box in step 5, it gets saved correctly, but not visible in the webui anywhere

@jkirschner-hashicorp
Copy link
Contributor

Thanks @shantanugadgil - I was able to reproduce using your steps and filed a new GH issue for that GUI behavior (#12073).

@blake blake closed this as completed May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/kv Issues related to the key value store type/bug Feature does not function as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants