Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

QOL: sort JSON on metrics/find API endpoint #1981

Merged

Conversation

GuillaumeConnan
Copy link
Contributor

This quality of life PR aims to sort the JSON returned by the metrics/find API endpoint, as the original Graphite-Web API.

The sort algorithm uses the Text field of each SeriesTree item.

Thus, the metrics tree appears alphabetically sorted on frontends like Grafana while exploring metrics or editing visualizations.

@stale
Copy link

stale bot commented Aug 22, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 22, 2021
@Dieterbe
Copy link
Contributor

The sort algorithm uses the Text field of each SeriesTree item.

why?

I notice the graphite-web code (find_view in metrics/views.py) uses this:

def json_nodes(nodes):
  nodes_info = []

  for node in nodes:
    info = dict(path=node.path, is_leaf=node.is_leaf)
    if node.is_leaf:
      info['intervals'] = [{'start': i.start, 'end': i.end} for i in node.intervals]

    nodes_info.append(info)

  return sorted(nodes_info, key=lambda item: item['path'])

@stale stale bot removed the stale label Aug 23, 2021
@Dieterbe
Copy link
Contributor

ah i see. FindTreejson sets the Text property to the node.Path field, so that should be equivalent then.

@Dieterbe
Copy link
Contributor

merci Guillaume !

@Dieterbe Dieterbe merged commit bc89bc9 into grafana:master Aug 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants