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

Maps embeddables in a dashboard not capturing map id in execution context #153218

Closed
rudolf opened this issue Mar 15, 2023 · 3 comments
Closed

Maps embeddables in a dashboard not capturing map id in execution context #153218

rudolf opened this issue Mar 15, 2023 · 3 comments
Assignees
Labels
Feature:Maps impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas

Comments

@rudolf
Copy link
Contributor

rudolf commented Mar 15, 2023

To reproduce:

  1. Install sample flights data
  2. Log elasticsearch queries by adding the following to kibana.yml
     logging:
       loggers:
         - name: elasticsearch.query
           level: debug
     logging.appenders.default:
        type: console
        layout:
          type: json
    
  3. Open the [Flights] Global Flight Dashboard

The X-Opaque-Id in the logs will contain entries like:

871c9395-5866-4135-99a9-e83c9858cc72;kibana:application:discover:new;application:dashboards:7adfa750-4c81-11e8-b3d7-01146121b73d;application:maps: // <-- NOTE missing map id makes it hard to attribute request to a specific map

In contrast to lens embeddables which create entries like:

871c9395-5866-4135-99a9-e83c9858cc72;kibana:application:discover:new;dashboard:dashboards:7adfa750-4c81-11e8-b3d7-01146121b73d;lens:lnsXY:0cc42484-16f7-42ec-b38c-9bf8be69cde7

Opening the map to edit it does produce the correct execution context, so it seems like the problem is the execution context is not correctly captured by the maps embeddable.

@botelastic botelastic bot added the needs-team Issues missing a team label label Mar 15, 2023
@nreese nreese added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. labels Mar 15, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

@botelastic botelastic bot removed the needs-team Issues missing a team label label Mar 15, 2023
@nreese
Copy link
Contributor

nreese commented Mar 20, 2023

Map id is not populated for embeddable maps because of the way executionContext is created by makePublicExecutionContext. makePublicExecutionContext does not take id as a parameter, instead getting id via executionContextServiceStart.get(). When a map is embedded, executionContextServiceStart.get() returns the id of the parent and not the id of the map so id in the map child context is not populated.

export function makePublicExecutionContext(description: string): KibanaExecutionContext {
  const topLevelContext = getExecutionContext().get();
  const context = makeExecutionContext({
    url: window.location.pathname,
    description,
  });

  // Distinguish between running in maps app vs. embedded
  return topLevelContext.name !== undefined && topLevelContext.name !== context.name
    ? {
        ...topLevelContext,
        child: context,
      }
    : {
        ...topLevelContext,
        ...context,
      };
}

@nreese nreese self-assigned this Mar 20, 2023
nreese added a commit that referenced this issue Mar 28, 2023
…ecution context (#153616)

#153218

Existing execution context implementation spread results from
`executionContextServiceStart().get()` to add map `id`. This
implementation did not work when map was embedded in another
application. When embedded, `executionContextServiceStart().get()`
returned the `id` of the parent application and not the `id` for the
map.

This PR resolves the issue by building executionContext directly in
MapEmbeddable and MapApp. MapApp uses `savedObjectId` for
`executionContext.id`. MapEmbeddable uses `embeddableId` for
`executionContext.id`.

The PR also updates the MVT routes to include executionContextId for the
execution context with `_mvt` calls.

#### Testing
To view execution context in kibana logs, add below to kibana.dev.yml.
For more information
https://www.elastic.co/guide/en/kibana/8.7/kibana-troubleshooting-trace-query.html
```
logging:
  loggers:
    - name: execution_context
      level: debug
      appenders: [console]
```

#### Execution context for lens and maps panels in dashboard
There is not a lot of consistency for what `type` and `name` should be
across Kibana. I found [this
comment](https://github.com/elastic/kibana/pull/105206/files#r671174649)
for when lens added execution context for lens embeddable that stated
`type:feature` and `name:sub_feature`. Therefore, I followed the lens
example and made `type:maps` and `name:maps` since maps does not have
sub_features.
 ```
[2023-03-23T18:29:12.750-06:00][DEBUG][execution_context]
{"type":"application","name":"dashboards","url":"/mth/app/dashboards","page":"app","id":"d98e6530-c9a8-11ed-9340-d743c2c88db8","child":{"type":"maps","name":"maps","id":"91f17723-367d-460e-ad90-dbac1fc072cb","url":"/map/de71f4f0-1902-11e9-919b-ffe5949a18d2","description":"es_geo_grid_source:cluster"}}
[2023-03-23T18:29:12.750-06:00][DEBUG][execution_context]
{"type":"application","name":"dashboards","url":"/mth/app/dashboards","page":"app","id":"d98e6530-c9a8-11ed-9340-d743c2c88db8","child":{"type":"maps","name":"maps","id":"91f17723-367d-460e-ad90-dbac1fc072cb","url":"/map/de71f4f0-1902-11e9-919b-ffe5949a18d2","description":"es_term_source:terms"}}
[2023-03-23T18:29:13.241-06:00][DEBUG][execution_context]
{"type":"dashboard","name":"dashboards","url":"/mth/app/dashboards","page":"app","id":"d98e6530-c9a8-11ed-9340-d743c2c88db8","description":"single
map","child":{"type":"lens","name":"lnsXY","id":"b9e44118-9e67-4c1c-9159-597d8a9f80d1","description":"lens","url":"/mth/app/lens#/edit/32e87880-c9ab-11ed-9340-d743c2c88db8"}}
```

#### Execution context for maps
There is not a lot of consistency across kibana for `type` and `name` in applications. [ExecutionContextService.getDefaultContext](https://github.com/elastic/kibana/blob/main/packages/core/execution-context/core-execution-context-browser-internal/src/execution_context_service.ts#L99) returns the below so I stuck with `application` for type in client and `server` for type in server. Here is [one more link](#124996) that provides some context value of `name` property.
```
return {
      type: 'application',
      name: this.appId,
      url: window.location.pathname,
    };
```

```
[2023-03-23T18:30:39.886-06:00][DEBUG][execution_context]
{"type":"application","name":"maps","url":"/mth/app/maps/map/de71f4f0-1902-11e9-919b-ffe5949a18d2","id":"de71f4f0-1902-11e9-919b-ffe5949a18d2","page":"editor","description":"es_geo_grid_source:cluster"}
[2023-03-23T18:30:39.886-06:00][DEBUG][execution_context]
{"type":"application","name":"maps","url":"/mth/app/maps/map/de71f4f0-1902-11e9-919b-ffe5949a18d2","id":"de71f4f0-1902-11e9-919b-ffe5949a18d2","page":"editor","description":"es_term_source:terms"}
```

---------

Co-authored-by: kibanamachine <[email protected]>
@nreese
Copy link
Contributor

nreese commented Mar 28, 2023

closed by #153616

@nreese nreese closed this as completed Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Maps impact:medium Addressing this issue will have a medium level of impact on the quality/strength of our product. Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants