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

cilium/cmd: improve 'bpf metrics list' JSON output #13731

Merged
merged 2 commits into from
Nov 16, 2020
Merged

cilium/cmd: improve 'bpf metrics list' JSON output #13731

merged 2 commits into from
Nov 16, 2020

Conversation

jibi
Copy link
Member

@jibi jibi commented Oct 23, 2020

This commit changes the JSON output for the 'bpf metrics list' command from the current format:

{
  "reason:0 dir:1": [
    "count:63752 bytes:20913476"
  ],
  "reason:0 dir:2": [
    "count:29697 bytes:2489416"
  ],
  "reason:132 dir:2": [
    "count:27 bytes:1930"
  ]
}

which is hard to parse even with tools such as jq to a more structured format:

[
  {
    "reason": 0,
    "description": "Success",
    "values": {
      "egress": {
        "packets": 29921,
        "bytes": 2508163
      },
      "ingress": {
        "packets": 64220,
        "bytes": 21064892
      }
    }
  },
  {
    "reason": 132,
    "description": "Invalid source ip",
    "values": {
      "egress": {
        "packets": 27,
        "bytes": 1930
      }
    }
  }
]

@jibi jibi requested a review from a team October 23, 2020 14:45
@jibi jibi requested review from a team as code owners October 23, 2020 14:45
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Oct 23, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot added this to In progress in 1.10.0 Oct 23, 2020
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, LGTM.

One thing I wonder is whether we are breaking any existing user scripts with this change.

cilium/cmd/bpf_metrics_list.go Show resolved Hide resolved
@fristonio fristonio added the release-note/minor This PR changes functionality that users may find relevant to operating Cilium. label Oct 26, 2020
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Oct 26, 2020
@aanm aanm added the dont-merge/wait-until-release Freeze window for current release is blocking non-bugfix PRs label Oct 26, 2020
@jibi
Copy link
Member Author

jibi commented Oct 26, 2020

Overall, LGTM.

One thing I wonder is whether we are breaking any existing user scripts with this change.

Yup, there was some discussion for that on slack and the conclusion was that it was fine as:

  • probably nobody is parsing this JSON given how broken it is
  • we don't really provide stability guarantees for things like map content dump

@aanm aanm removed the dont-merge/wait-until-release Freeze window for current release is blocking non-bugfix PRs label Nov 10, 2020
@aanm
Copy link
Member

aanm commented Nov 11, 2020

test-me-please

Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is undoubtedly an improvement! The parsing is a little too fragile for my taste but there's unit test coverage and it seems to do the job.

However, the output differs from the suggested format in #13492. Would you mind explaining the rationale for choosing a map with the reason number as string for keys rather than a list of objects which include the reason as in #13492?

@jibi
Copy link
Member Author

jibi commented Nov 11, 2020

This is undoubtedly an improvement! The parsing is a little too fragile for my taste but there's unit test coverage and it seems to do the job.

I agree with that, but making it more robust would require changing how the metricsmap package exposes the metrics map, which is beyond the scope of this PR

However, the output differs from the suggested format in #13492. Would you mind explaining the rationale for choosing a map with the reason number as string for keys rather than a list of objects which include the reason as in #13492?

No strong reason (and I'm happy to switch to a list of objects if you think that would be better 👍 ).
As you pointed out #13492 was just suggesting an option and the main reason for me to pick a map was to make it easier to parse what I assumed would be the most common query, i.e. getting metrics for a given reason:

➜  ~ jq '.["132"]' format1.json
{
  "description": "Invalid source ip",
  "values": {
    "egress": {
      "packets": 27,
      "bytes": 1930
    }
  }
}

(or even more compact: jq '{"132"}' format1.json)

vs

➜  ~ jq '.[] | select(.reason == 139)' format2.json
{
  "reason": 139,
  "values": {
    "ingress": {
      "count": 16,
      "bytes": 1668
    }
  }
}

@rolinh
Copy link
Member

rolinh commented Nov 11, 2020

Disclaimer: I'm don't consume the output of cilium bpf metrics list so my opinion is only given from an API/readability perspective.

As you pointed out #13492 was just suggesting an option and the main reason for me to pick a map was to make it easier to parse what I assumed would be the most common query, i.e. getting metrics for a given reason

This sounds like a good reason. The main reason I prefer the version suggested by @qmonnet in #13492 is that it is more descriptive. When I look at it, "reason": 0, is self-explanatory whereas with the current output, it's not explicit what the key "0" is unless I somehow acquire knowledge about it. I think the list version might also be a little more robust. For instance, how would you query metrics for multiple reasons with jq with both versions?

@jibi
Copy link
Member Author

jibi commented Nov 11, 2020

As you pointed out #13492 was just suggesting an option and the main reason for me to pick a map was to make it easier to parse what I assumed would be the most common query, i.e. getting metrics for a given reason

This sounds like a good reason. The main reason I prefer the version suggested by @qmonnet in #13492 is that it is more descriptive. When I look at it, "reason": 0, is self-explanatory whereas with the current output, it's not explicit what the key "0" is unless I somehow acquire knowledge about it. I think the list version might also be a little more robust.

I think that's also a good argument 👍

For instance, how would you query metrics for multiple reasons with jq with both versions?

➜  ~ jq '{"0", "132"}' format1.json
{
  "0": {
    "description": "Success",
    "values": {
      "egress": {
        "packets": 29921,
        "bytes": 2508163
      },
      "ingress": {
        "packets": 64220,
        "bytes": 21064892
      }
    }
  },
  "132": {
    "description": "Invalid source ip",
    "values": {
      "egress": {
        "packets": 27,
        "bytes": 1930
      }
    }
  }
}

vs

➜  ~ jq '.[] | select(.reason == 0 or .reason == 139)' format2.json
{
  "reason": 0,
  "values": {
    "ingress": {
      "count": 3682036,
      "bytes": 344283040
    },
    "egress": {
      "count": 4900066,
      "bytes": 1675309710
    }
  }
}
{
  "reason": 139,
  "values": {
    "ingress": {
      "count": 16,
      "bytes": 1668
    }
  }
}

So the map based approach would led to a more concise jq command. But beside that I don't feel strongly about any of the 2 options 🤔

@rolinh
Copy link
Member

rolinh commented Nov 11, 2020

I don't feel strongly about any of the 2 options

I don't feel strongly about either approaches as well although the list version looks more like what I would expect.

@jibi
Copy link
Member Author

jibi commented Nov 11, 2020

I don't feel strongly about any of the 2 options

I don't feel strongly about either approaches as well although the list version looks more like what I would expect.

Let's go for the list approach then 👍

@jibi
Copy link
Member Author

jibi commented Nov 11, 2020

Switched to a list ✔️

@jibi
Copy link
Member Author

jibi commented Nov 11, 2020

test-me-please

Copy link
Member

@christarazi christarazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output looks good to me, I like the list. A few comments below.

cilium/cmd/bpf_metrics_list.go Outdated Show resolved Hide resolved
cilium/cmd/bpf_metrics_list.go Outdated Show resolved Hide resolved
cilium/cmd/bpf_metrics_list_test.go Outdated Show resolved Hide resolved
pkg/maps/metricsmap/metricsmap.go Outdated Show resolved Hide resolved
Signed-off-by: Gilberto Bertin <gilberto@isovalent.com>
@jibi
Copy link
Member Author

jibi commented Nov 12, 2020

I should have addressed all comments 👍

@jibi
Copy link
Member Author

jibi commented Nov 12, 2020

test-me-please

This commit changes the JSON output for the 'bpf metrics list'
command from the current format:

```js
{
  "reason:0 dir:1": [
    "count:63752 bytes:20913476"
  ],
  "reason:0 dir:2": [
    "count:29697 bytes:2489416"
  ],
  "reason:132 dir:2": [
    "count:27 bytes:1930"
  ]
}
```

which is hard to parse even with tools such as jq to a more structured
format:

```js
[
  {
    "reason": 0,
    "description": "Success",
    "values": {
      "egress": {
        "packets": 29921,
        "bytes": 2508163
      },
      "ingress": {
        "packets": 64220,
        "bytes": 21064892
      }
    }
  },
  {
    "reason": 132,
    "description": "Invalid source ip",
    "values": {
      "egress": {
        "packets": 27,
        "bytes": 1930
      }
    }
  }
]
```

Fixes: #13492

Signed-off-by: Gilberto Bertin <gilberto@isovalent.com>
@jibi
Copy link
Member Author

jibi commented Nov 12, 2020

test-me-please

@jibi
Copy link
Member Author

jibi commented Nov 12, 2020

test-gke

Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

Copy link
Member

@rolinh rolinh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Nov 16, 2020
@aanm aanm merged commit 8bb5a2d into cilium:master Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/minor This PR changes functionality that users may find relevant to operating Cilium.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants