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

Add stats API for maps and layers in maps plugin #362

Merged
merged 3 commits into from
Apr 5, 2023

Conversation

junqiu-lei
Copy link
Member

@junqiu-lei junqiu-lei commented Mar 28, 2023

Description

Add maps metrics api to get stats from maps saved object.

It has several metrics related to map layers and maps, including the total number of maps, the number of layers of different types, and information about each map.

GET /api/maps-dashboards/stats

Response content example:

{
   "maps_total":4,
   "layers_filters_total":4,
   "layers_total":{
      "opensearch_vector_tile_map":2,
      "documents":7,
      "wms":1,
      "tms":2
   },
   "maps_list":[
      {
         "id":"88a24e6c-0216-4f76-8bc7-c8db6c8705da",
         "layers_filters_total":4,
         "layers_total":{
            "opensearch_vector_tile_map":1,
            "documents":3,
            "wms":0,
            "tms":0
         }
      },
      {
         "id":"4ce3fe50-d309-11ed-a958-770756e00bcd",
         "layers_filters_total":0,
         "layers_total":{
            "opensearch_vector_tile_map":0,
            "documents":2,
            "wms":0,
            "tms":1
         }
      },
      {
         "id":"af5d3b90-d30a-11ed-a605-f7ad7bc98642",
         "layers_filters_total":0,
         "layers_total":{
            "opensearch_vector_tile_map":1,
            "documents":1,
            "wms":0,
            "tms":1
         }
      },
      {
         "id":"5ca1ec10-d30b-11ed-a042-93d8ff0f09ee",
         "layers_filters_total":0,
         "layers_total":{
            "opensearch_vector_tile_map":0,
            "documents":1,
            "wms":1,
            "tms":0
         }
      }
   ]
}

Issues Resolved

#363

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@704bb13). Click here to learn what that means.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##             main     #362   +/-   ##
=======================================
  Coverage        ?   73.33%           
=======================================
  Files           ?       26           
  Lines           ?      675           
  Branches        ?      103           
=======================================
  Hits            ?      495           
  Misses          ?      152           
  Partials        ?       28           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@joshuali925 joshuali925 left a comment

Choose a reason for hiding this comment

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

lgtm

server/common/metrics/type.ts Outdated Show resolved Hide resolved
@junqiu-lei junqiu-lei changed the title Add maps metrics api from saved object Add maps stats api from saved object Mar 30, 2023
@junqiu-lei junqiu-lei force-pushed the metrics_1 branch 3 times, most recently from 0249a44 to 7c74a3d Compare March 31, 2023 17:32
CHANGELOG.md Outdated
@@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Infrastructure
* Add CHANGELOG ([#342](https://github.com/opensearch-project/dashboards-maps/pull/342))
* Add maps metrics api from saved object ([#362](https://github.com/opensearch-project/dashboards-maps/pull/362))
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should better frame this feature.

Copy link
Member Author

@junqiu-lei junqiu-lei Apr 5, 2023

Choose a reason for hiding this comment

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

Some of options, WDYT?

  • Add stats API for maps and layers in maps plugin (applied in PR)
  • Add endpoint to retrieve maps and layers statistics in maps plugin
  • Get maps and layers stats in maps plugin

Also feel free to give other suggestions, thanks!

Copy link
Collaborator

@navneet1v navneet1v Apr 5, 2023

Choose a reason for hiding this comment

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

  • Add stats API for maps and layers in maps plugin

This should work.

Lets make sure when we merge the commits we use this same commit message

server/routes/stats_router.ts Outdated Show resolved Hide resolved
server/routes/stats_router.ts Show resolved Hide resolved
server/routes/stats_router.ts Outdated Show resolved Hide resolved
server/routes/stats_router.ts Show resolved Hide resolved
server/common/stats/stats_helper.ts Outdated Show resolved Hide resolved
server/common/stats/stats_helper.ts Outdated Show resolved Hide resolved
server/common/stats/stats_helper.test.ts Show resolved Hide resolved
Signed-off-by: Junqiu Lei <junqiu@amazon.com>
Signed-off-by: Junqiu Lei <junqiu@amazon.com>
try {
const savedObjectsClient = context.core.savedObjects.client;
const mapsSavedObjects: SavedObjectsFindResponse<MapSavedObjectAttributes> =
await savedObjectsClient?.find({ type: MAP_SAVED_OBJECT_TYPE, perPage: 1000, page: 1 });
Copy link
Member

Choose a reason for hiding this comment

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

does this mean get only 1000 Maps ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we have define a number here, the default is 20 in 1 page to response, which is obviously not enough.

Copy link
Member

Choose a reason for hiding this comment

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

What if there are 1001 Maps? Are we iterating page?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here to have iteration request, per request will have 50 maps

Signed-off-by: Junqiu Lei <junqiu@amazon.com>
@junqiu-lei junqiu-lei requested a review from VijayanB April 5, 2023 16:45
@navneet1v navneet1v changed the title Add maps stats api from saved object Add stats API for maps and layers in maps plugin Apr 5, 2023
@junqiu-lei junqiu-lei merged commit ef5be8e into opensearch-project:main Apr 5, 2023
@junqiu-lei junqiu-lei deleted the metrics_1 branch April 5, 2023 17:07
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 5, 2023
* Add stats API for maps and layers in maps plugin

Signed-off-by: Junqiu Lei <junqiu@amazon.com>
(cherry picked from commit ef5be8e)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 5, 2023
* Add stats API for maps and layers in maps plugin

Signed-off-by: Junqiu Lei <junqiu@amazon.com>
(cherry picked from commit ef5be8e)
junqiu-lei added a commit that referenced this pull request Apr 5, 2023
* Add stats API for maps and layers in maps plugin

Signed-off-by: Junqiu Lei <junqiu@amazon.com>
(cherry picked from commit ef5be8e)

Co-authored-by: Junqiu Lei <junqiu@amazon.com>
junqiu-lei added a commit that referenced this pull request Apr 5, 2023
* Add stats API for maps and layers in maps plugin

Signed-off-by: Junqiu Lei <junqiu@amazon.com>
(cherry picked from commit ef5be8e)

Co-authored-by: Junqiu Lei <junqiu@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants