Custom metric for aggregation based visualizations

Hello :wave:

I'm trying to migrate the famous plugin datasweet formula but I'm stuck.

I created a custom metric using the registerMetric function from the data plugin and the metric appears except options. I want to create "custom options" like select and textarea but I can't find a way to do it.

Any ideas ? :slight_smile:

That's a pretty old plugin by the looks of it, and it's not a core one, so you'd need to approach the developer.

I don't know Vega intimately, but I'd suggest that might be a better approach as it can do custom functions.

Have you looked at custom formulas in Lens?

1 Like

Ahh yeah, even easier!

This is a good alternative to datasweet, thank you.

But, I have the same problem with an other custom metric and I don't understand why I'm not able to create specific params for my metrics anymore :sob:

Do you know if the lens team plans to add the ability to create custom functions and visualizations ?

Vega is a visualization plugin. When you create a visualization plugin, you have the ability to create your own configuration panel.

In my case, I want only create a metric accessible by all agregations based visualization.

Perhaps if you give more detail / example we could help, I am not sure what you are asking..

Can you provide an example and the equation

You're aright, it will be easier with an example :slight_smile:

To illustrate my problem, I created a custom metric that display a specific value.
This custom metric has two parameters. The first one is an string input to provide the value to display and the second one is a select containing some options.

To set up this example, I used a MetricAggType object as following :

new MetricAggType({
    name: 'custom_metric',
    expressionName: aggCustomFnName,
    title: 'Custom metric',
    type: 'metrics',
    subtype: 'Customs',
    hasNoDsl: true,
    makeLabel(aggConfig) {
      return 'Custom ' + aggConfig.id;
    },
    params: [
      {
        name: 'value',
        displayName: 'Value',
        type: 'string',
      },
      {
        name: 'option',
        displayName: 'Option',
        type: 'optioned',
        options: [
          {
            text: i18n.translate('option1', {
              defaultMessage: 'Option1',
            }),
            isCompatible: true,
            disabled: false,
            value: 'option1',
          },
          {
            text: i18n.translate('option2', {
              defaultMessage: 'Option2',
            }),
            isCompatible: true,
            disabled: false,
            value: 'option2',
          },
        ],
        write: _.noop,
      },
    ],
    getSerializedFormat(agg) {
      return fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.NUMBER);
    },
    getValue(agg: any, bucket: any) {
      return agg.params.value;
    },
  });

Unfortunately, the select is not displayed :

In previous version of Kibana, I can use the editorComponent property to render parameters but this property was removed.

Apologies I am a bit dense this AM I am not sure what the resulting Visualization is supposed to look like.

Were is the select option supposed to be on the display? Does it change the Color.. is used at the label?

What you are showing is not Lens and not the Custom Formula Section which you should be able to access multiple fields

That said Vega is extremely flexible perhaps take a look at that.

I'm currently in the same use case as pchakour, I made a custom metric named stats to use the power of elasticsearch to make a single query and retrieve all results from the extended_stats metric. The user can select the part of the answer they don't want or all the results.

This metric helps to reduce the visualization setup when the user wants multiple results on a single field.

With the new version of Kibana, we cannot insert this custom metric without patching the code. It's sad to close to the community the ability to enrich the solution.

Would it be possible to open the solution to make a custom metric integration in Lens or in all visualizations as before?

@ghudgins Any Thoughts on the Above? I am unclear?

In previous version of Kibana, I can use the editorComponent property to render parameters but this property was removed.

I don't think we intentionally closed anything off, I'm not familiar with this plugin or how it works but if it's targeting DOM elements via CSS to add the select option there's a chance the CSS changed and the plugin needs updating. I'll see if I can try it out

Also generally will be looking into this plugin's unique abilities over things like runtime fields and lens custom formula to see if there's an enhancement request in there.

The user can select the part of the answer they don't want or all the results.

it sounds like adding the controls to the editor is the key difference?

Ok thanks ! I will continue on my side... I'm also taking a look to Lens Formula to replace Datasweet formula.

It will be great !! Lens will become more popular and extensibility will be the key for the community to improve Lens.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.