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

[Actions] Fixed actions telemetry for multiple namespaces usage #114748

Merged

Conversation

YulNaumenko
Copy link
Contributor

@YulNaumenko YulNaumenko commented Oct 13, 2021

Summary

Current PR fixing the bug in actions telemetry, when connectors and actions were created in multiple spaces.
After making actions saved object 'multiple-isolated', we didn't change the action telemetry task, which used SavedObjects bulkGet method, which has next restrictions for the namespaces search:

For isolated object types (registered with `namespaceType: 'single'` or `namespaceType: 'multiple-isolated'`): 
this option can only be used to specify a single space, and the "All spaces" identifier (`'*'`) is not allowed. 

That's why for the objects created in non default space, the error message in console was appeared each time the telemetry task was executed.

Steps to reproduce:

  1. Create multiple spaces
  2. In each space create a rule with actions
  3. Run telemetry task and observe the error message in the console log
    Error executing actions telemetry task: TypeError: Cannot read property 'actionTypeId' of undefined.

@YulNaumenko YulNaumenko added bug Fixes for quality problems that affect the customer experience v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.16.0 Feature:Actions/Framework Issues related to the Actions Framework labels Oct 13, 2021
@YulNaumenko YulNaumenko self-assigned this Oct 13, 2021
@YulNaumenko YulNaumenko requested a review from a team as a code owner October 13, 2021 03:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-alerting-services (Team:Alerting Services)

@chrisronline
Copy link
Contributor

@YulNaumenko I'm not able to reproduce this.

I have three rules, each with a server log connector in three separate spaces and I'm not seeing any errors in the Kibana server log when I access https://localhost:5601/api/stats?extended. I even changed the telemetry task to run over and over (instead of once a day)

Rule SOs
[
  {
    "_index" : ".kibana_8.0.0_001",
    "_id" : "alert:306cdf20-2c2b-11ec-986b-95490e9a4a19",
    "_score" : 1.5994332,
    "_source" : {
      "alert" : {
        "params" : {
          "esQuery" : """{
"query":{
"match_all" : {}
}
}""",
          "size" : 100,
          "timeWindowSize" : 5,
          "timeWindowUnit" : "m",
          "threshold" : [
            0
          ],
          "thresholdComparator" : ">",
          "index" : [
            ".kibana-event-log-*"
          ],
          "timeField" : "@timestamp"
        },
        "consumer" : "alerts",
        "schedule" : {
          "interval" : "1m"
        },
        "tags" : [ ],
        "name" : "ESQueryTest",
        "throttle" : null,
        "actions" : [
          {
            "group" : "query matched",
            "params" : {
              "level" : "info",
              "message" : "Hey chris, from ChrisSpace"
            },
            "actionRef" : "preconfigured:my_server_log",
            "actionTypeId" : ".server-log"
          }
        ],
        "enabled" : true,
        "alertTypeId" : ".es-query",
        "notifyWhen" : "onActiveAlert",
        "apiKeyOwner" : "elastic",
        "apiKey" : "O1ioTQF99Viupma4qHvHbxdBuGtTj9OTfQKbp/Qn0RgC5LQQDVaE8SUu0J07+gdcErZrMLRdkWF9sQL3Jw+P9gvbbWe9Mi2QYEIV6qrbOkBByX/SfbzyzzpQKYzcB702Z68shBhT43oH3xamyd4RuQQsk0lQAqpI4zMD238tVg9ocgsYZf1FEY1cSn35Xas2fvtVcUMTqCvMNw==",
        "legacyId" : null,
        "createdBy" : "elastic",
        "updatedBy" : "elastic",
        "createdAt" : "2021-10-13T13:40:55.953Z",
        "updatedAt" : "2021-10-13T13:42:18.157Z",
        "muteAll" : false,
        "mutedInstanceIds" : [ ],
        "executionStatus" : {
          "status" : "active",
          "lastExecutionDate" : "2021-10-13T14:11:36.393Z",
          "error" : null,
          "lastDuration" : 469
        },
        "meta" : {
          "versionApiKeyLastmodified" : "8.0.0"
        },
        "scheduledTaskId" : "315ee040-2c2b-11ec-986b-95490e9a4a19"
      },
      "type" : "alert",
      "references" : [ ],
      "namespaces" : [
        "christest"
      ],
      "migrationVersion" : {
        "alert" : "8.0.0"
      },
      "coreMigrationVersion" : "8.0.0",
      "updated_at" : "2021-10-13T14:11:36.863Z"
    }
  },
  {
    "_index" : ".kibana_8.0.0_001",
    "_id" : "alert:57ad3df0-2c2b-11ec-986b-95490e9a4a19",
    "_score" : 1.5994332,
    "_source" : {
      "alert" : {
        "params" : {
          "esQuery" : """{
"query":{
"match_all" : {}
}
}""",
          "size" : 100,
          "timeWindowSize" : 5,
          "timeWindowUnit" : "m",
          "threshold" : [
            0
          ],
          "thresholdComparator" : ">",
          "index" : [
            ".kibana-event-log-*"
          ],
          "timeField" : "@timestamp"
        },
        "consumer" : "alerts",
        "schedule" : {
          "interval" : "1m"
        },
        "tags" : [ ],
        "name" : "ESQueryTest",
        "throttle" : null,
        "actions" : [
          {
            "group" : "query matched",
            "params" : {
              "level" : "info",
              "message" : "Hey chris, from RobersonSpace"
            },
            "actionRef" : "preconfigured:my_server_log",
            "actionTypeId" : ".server-log"
          }
        ],
        "enabled" : true,
        "alertTypeId" : ".es-query",
        "notifyWhen" : "onActiveAlert",
        "apiKeyOwner" : "elastic",
        "apiKey" : "F88QssS0WgBeynKO+SGAPn/8fjCEcaMJFyPZUMnbCGFK05KhkDgs98nFYAhUNJNOGDWvlMoURaAthqj9sv/DaM9xJ/xb6bals0NvbH2ypFU7WxdqP2cnm4CBpNI06JXe9beyUqnTXv6BgqSgA6u2tiITa47Nod72OIWZkJuULr44DsCz6BEXtkRje5FKnziDymtZpXdFy1ZRVg==",
        "legacyId" : null,
        "createdBy" : "elastic",
        "updatedBy" : "elastic",
        "createdAt" : "2021-10-13T13:42:01.061Z",
        "updatedAt" : "2021-10-13T13:42:01.061Z",
        "muteAll" : false,
        "mutedInstanceIds" : [ ],
        "executionStatus" : {
          "status" : "active",
          "lastExecutionDate" : "2021-10-13T14:11:36.393Z",
          "error" : null,
          "lastDuration" : 516
        },
        "meta" : {
          "versionApiKeyLastmodified" : "8.0.0"
        },
        "scheduledTaskId" : "57fe4420-2c2b-11ec-986b-95490e9a4a19"
      },
      "type" : "alert",
      "references" : [ ],
      "namespaces" : [
        "robersontest"
      ],
      "migrationVersion" : {
        "alert" : "8.0.0"
      },
      "coreMigrationVersion" : "8.0.0",
      "updated_at" : "2021-10-13T14:11:36.911Z"
    }
  },
  {
    "_index" : ".kibana_8.0.0_001",
    "_id" : "alert:497e06c0-2b8a-11ec-b0c1-2b512cd520ea",
    "_score" : 1.5994332,
    "_source" : {
      "alert" : {
        "params" : {
          "esQuery" : """{
"query":{
"match_all" : {}
}
}""",
          "size" : 100,
          "timeWindowSize" : 5,
          "timeWindowUnit" : "m",
          "threshold" : [
            0
          ],
          "thresholdComparator" : ">",
          "index" : [
            ".kibana-event-log-*"
          ],
          "timeField" : "@timestamp"
        },
        "consumer" : "alerts",
        "schedule" : {
          "interval" : "1m"
        },
        "tags" : [ ],
        "name" : "ESQueryTest",
        "throttle" : null,
        "actions" : [
          {
            "group" : "query matched",
            "params" : {
              "level" : "info",
              "message" : "Hey chris"
            },
            "actionRef" : "preconfigured:my_server_log",
            "actionTypeId" : ".server-log"
          }
        ],
        "enabled" : true,
        "alertTypeId" : ".es-query",
        "notifyWhen" : "onActiveAlert",
        "apiKeyOwner" : "elastic",
        "apiKey" : "6tqz7EKd+q9cOXkjWrl0k6dpGr7sN9AJbdIwTbWVfQRJOxu+i5T+/cmWfphRXf8RCg2R/cyWFZwlZlNdtK1zH4/m2XBBxT60sTlT1Hmav93hypJdZBittUXLBh0yz8nt7F+0+e0f0tX/itVEGZWNiEHWCw1LqFgxExaaT9B+BfdKPfd790WxFLkwg8ihagiNLB1pOw9kP4Y87Q==",
        "legacyId" : null,
        "createdBy" : "elastic",
        "updatedBy" : "elastic",
        "createdAt" : "2021-10-12T18:29:08.316Z",
        "updatedAt" : "2021-10-12T19:44:14.317Z",
        "muteAll" : false,
        "mutedInstanceIds" : [ ],
        "executionStatus" : {
          "status" : "active",
          "lastExecutionDate" : "2021-10-13T14:11:36.392Z",
          "error" : null,
          "lastDuration" : 518
        },
        "meta" : {
          "versionApiKeyLastmodified" : "8.0.0"
        },
        "scheduledTaskId" : "4a1ae300-2b8a-11ec-b0c1-2b512cd520ea"
      },
      "type" : "alert",
      "references" : [ ],
      "namespaces" : [
        "default"
      ],
      "migrationVersion" : {
        "alert" : "8.0.0"
      },
      "coreMigrationVersion" : "8.0.0",
      "updated_at" : "2021-10-13T14:11:36.912Z"
    }
  }
]
Kibana server log
 [2021-10-13T10:12:42.413-04:00][INFO ][plugins.actions] Server log: Hey chris, from ChrisSpace
 [2021-10-13T10:12:42.415-04:00][INFO ][plugins.actions] Server log: Hey chris, from RobersonSpace
 [2021-10-13T10:13:45.474-04:00][INFO ][plugins.actions] Server log: Hey chris
 [2021-10-13T10:13:45.475-04:00][INFO ][plugins.actions] Server log: Hey chris, from RobersonSpace
 [2021-10-13T10:13:45.477-04:00][INFO ][plugins.actions] Server log: Hey chris, from ChrisSpace

@ymao1
Copy link
Contributor

ymao1 commented Oct 13, 2021

I am seeing this error: [2021-10-13T13:55:02.546-04:00][WARN ][plugins.actions.usage] Error executing actions telemetry task: TypeError: Cannot read property 'actionTypeId' of undefined. Is this the expected error?

@YulNaumenko
Copy link
Contributor Author

I am seeing this error: [2021-10-13T13:55:02.546-04:00][WARN ][plugins.actions.usage] Error executing actions telemetry task: TypeError: Cannot read property 'actionTypeId' of undefined. Is this the expected error?

Yes , exactly! I'm sorry I didn't include the clarification for this.

@chrisronline
Copy link
Contributor

Ah I see. This only happens for non preconfigured connectors

@YulNaumenko
Copy link
Contributor Author

YulNaumenko commented Oct 13, 2021

@YulNaumenko I'm not able to reproduce this.

I have three rules, each with a server log connector in three separate spaces and I'm not seeing any errors in the Kibana server log when I access https://localhost:5601/api/stats?extended. I even changed the telemetry task to run over and over (instead of once a day)

It's my bad, I didn't put more details on the error you expect to see. @ymao1 described above the error in the console log which appears as the result.
Basically this is happened because some actions returned like:

[
{
   id: '1',
   error: ErrorObject,
},
{ 
  id: '2',
  actionTypeId: '.server-log'
}
] 

@YulNaumenko
Copy link
Contributor Author

Ah I see. This only happens for non preconfigured connectors

For preconfigured it is not relevant because they are space agnostic.

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

LGTM! Great work!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @YulNaumenko

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM!

This doesn't need to be backported right? Because rules & connectors are still 'single' namespace type in 7.x? I would update the labels to remove v7.16.0 and add backport-skip

@YulNaumenko
Copy link
Contributor Author

YulNaumenko commented Oct 13, 2021

LGTM!

This doesn't need to be backported right? Because rules & connectors are still 'single' namespace type in 7.x? I would update the labels to remove v7.16.0 and add backport-skip

After some thinking about it, probably that's better to backport it to be safe the error won't happened in 7.16. The logic was not changed, just the way it is implemented.

@YulNaumenko YulNaumenko merged commit c737c39 into elastic:master Oct 13, 2021
YulNaumenko added a commit to YulNaumenko/kibana that referenced this pull request Oct 13, 2021
…tic#114748)

* [Actions] Fixed actions telemetry for multiple namespaces usage

* fixed tests
YulNaumenko added a commit that referenced this pull request Oct 13, 2021
) (#114923)

* [Actions] Fixed actions telemetry for multiple namespaces usage

* fixed tests
jloleysens added a commit to jloleysens/kibana that referenced this pull request Oct 14, 2021
…mple/introduce-baseline-tests

* 'master' of github.com:elastic/kibana: (55 commits)
  [Fleet] Improve Functionality around Managed Package Policies (elastic#114526)
  cleanup (elastic#114902)
  remove stray semicolon (elastic#114969)
  [Security Solution] Edit host isolation exception IP UI (elastic#114279)
  [ML] APM Correlations: Round duration values to be used in range aggregations. (elastic#114833)
  [Index Management] Added `data-test-subj` values to the index context menu buttons (elastic#114900)
  [Stack monitoring] Fix logstash functional tests for react (elastic#114819)
  Implement hybrid approach to writing rule execution event logs (elastic#114852)
  [Detection Rules] Add 7.16 rules (elastic#114939)
  Fixing exceptions export format (elastic#114920)
  Clean up inaccurate comments (elastic#114935)
  chore(NA): fixes a typo on persist_bazel_cache.sh comment (elastic#114943)
  [ci] Fixes Bazel cache writes (elastic#114915)
  fix package.json: (elastic#114936)
  [Controls] Redux Toolkit and Embeddable Redux Wrapper (elastic#114371)
  [APM] Fixes incorrect index config names (elastic#114901) (elastic#114904)
  [Workplace Search] Fix button order and remove extra source name label (elastic#114899)
  [Actions] Fixed actions telemetry for multiple namespaces usage (elastic#114748)
  docs: fix config names (elastic#114903)
  Update kibana to EMS 7.16 (elastic#114865)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Actions/Framework Issues related to the Actions Framework release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants