customurl.asciidoc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. [role="xpack"]
  2. [[ml-configuring-url]]
  3. === Adding custom URLs to machine learning results
  4. When you create an advanced {anomaly-job} or edit any {anomaly-jobs} in {kib},
  5. you can optionally attach one or more custom URLs.
  6. The custom URLs provide links from the anomalies table in the *Anomaly Explorer*
  7. or *Single Metric Viewer* window in {kib} to {kib} dashboards, the *Discovery*
  8. page, or external websites. For example, you can define a custom URL that
  9. provides a way for users to drill down to the source data from the results set.
  10. When you edit an {anomaly-job} in {kib}, it simplifies the creation of the
  11. custom URLs for {kib} dashboards and the *Discover* page and it enables you to
  12. test your URLs. For example:
  13. [role="screenshot"]
  14. image::images/ml-customurl-edit.jpg["Edit a job to add a custom URL"]
  15. For each custom URL, you must supply the URL and a label, which is the link text
  16. that appears in the anomalies table. You can also optionally supply a time
  17. range. For example, these are the values that are added for `My link 1`:
  18. [role="screenshot"]
  19. image::images/ml-customurl-detail.jpg["An example of a label and URL"]
  20. As in this case, the custom URL can contain
  21. <<ml-configuring-url-strings,dollar sign delimited tokens>>, which
  22. are populated when you click the link in the anomalies table. In this example,
  23. the custom URL contains `$earliest$`, `$latest$`, and `$service$` tokens, which
  24. pass the beginning and end of the time span of the selected anomaly and the
  25. pertinent `service` field value to the target page. If you were interested in
  26. the following anomaly, for example:
  27. [role="screenshot"]
  28. image::images/ml-customurl.jpg["An example of the custom URL links in the Anomaly Explorer anomalies table"]
  29. ...clicking `My Link 1` opens the *Discover* page and shows results for the
  30. service and date that were identified in the anomaly:
  31. [role="screenshot"]
  32. image::images/ml-customurl-discover.jpg["An example of the results on the Discover page"]
  33. Since we specified a time range of 2 hours, the time filter restricts the
  34. results to the time period two hours before and after the anomaly.
  35. You can also specify these custom URL settings when you create or update
  36. {anomaly-jobs} by using the APIs.
  37. [float]
  38. [[ml-configuring-url-strings]]
  39. ==== String substitution in custom URLs
  40. You can use dollar sign ($) delimited tokens in a custom URL. These tokens are
  41. substituted for the values of the corresponding fields in the anomaly records.
  42. For example, for a configured URL of
  43. `http://my.datastore.com/dashboards?user=$user_name$`, the value of the
  44. `user_name` field in the anomaly record is substituted into the `$user_name$`
  45. token when you click the link in the anomalies table.
  46. NOTE: Not all fields in your source data exist in the anomaly results. If a
  47. field is specified in the detector as the `field_name`, `by_field_name`,
  48. `over_field_name`, or `partition_field_name`, for example, it can be used in a
  49. custom URL. A field that is only used in the `categorization_field_name`
  50. property, however, does not exist in the anomaly results.
  51. The following keywords can also be used as tokens for string substitution in a
  52. custom URL: `$earliest$`; `$latest$`; `$mlcategoryregex$`; `$mlcategoryterms$`.
  53. The `$earliest$` and `$latest$` tokens pass the beginning and end of the time
  54. span of the selected anomaly to the target page. The tokens are substituted with
  55. date-time strings in ISO-8601 format. If you selected an interval of 1 hour for
  56. the anomalies table, these tokens use one hour on either side of the anomaly
  57. time as the earliest and latest times. The same is also true if the interval is
  58. set to `Auto` and a one hour interval was chosen. You can override this behavior
  59. by using the `time_range` setting.
  60. The `$mlcategoryregex$` and `$mlcategoryterms$` tokens pertain to {anomaly-jobs}
  61. where you are categorizing field values. For more information about this type of
  62. analysis, see <<ml-configuring-categories>>.
  63. The `$mlcategoryregex$` token passes the regular expression value of the
  64. category of the selected anomaly, as identified by the value of the `mlcategory`
  65. field of the anomaly record.
  66. The `$mlcategoryterms$` token likewise passes the terms value of the category of
  67. the selected anomaly. Each categorization term is prefixed by a plus (+)
  68. character, so that when the token is passed to a {kib} dashboard, the resulting
  69. dashboard query seeks a match for all of the terms of the category.
  70. For example, the following API updates a job to add a custom URL that uses
  71. `$earliest$`, `$latest$`, and `$mlcategoryterms$` tokens:
  72. [source,console]
  73. ----------------------------------
  74. POST _ml/anomaly_detectors/sample_job/_update
  75. {
  76. "custom_settings": {
  77. "custom_urls": [
  78. {
  79. "url_name": "test-link1",
  80. "time_range": "1h",
  81. "url_value": "http://localhost:5601/app/kibana#/discover?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:'$earliest$',mode:quick,to:'$latest$'))&_a=(columns:!(_source),index:AV3OWB68ue3Ht69t29aw,interval:auto,query:(query_string:(analyze_wildcard:!t,query:'$mlcategoryterms$')),sort:!(time,desc))"
  82. }
  83. ]
  84. }
  85. }
  86. ----------------------------------
  87. //TEST[skip:setup:sample_job]
  88. When you click this custom URL in the anomalies table in {kib}, it opens up the
  89. *Discover* page and displays source data for the period one hour before and
  90. after the anomaly occurred. Since this job was categorizing log messages, some
  91. `$mlcategoryterms$` token values that were passed to the target page for an
  92. example anomaly are as follows:
  93. [role="screenshot"]
  94. image::images/ml-categoryterms.jpg["A query for category terms on the Discover page in {kib}"]
  95. [TIP]
  96. ===============================
  97. * The custom URL links in the anomaly tables use pop-ups. You must configure
  98. your web browser so that it does not block pop-up windows or create an exception
  99. for your {kib} URL.
  100. * When creating a link to a {kib} dashboard, the URLs for dashboards can be very
  101. long. Be careful of typos, end of line characters, and URL encoding. Also ensure
  102. you use the appropriate index ID for the target {kib} index pattern.
  103. * If you use an influencer name for string substitution, keep in mind that it
  104. might not always be available in the analysis results and the URL is invalid in
  105. those cases. There is not always a statistically significant influencer for each
  106. anomaly.
  107. * The dates substituted for `$earliest$` and `$latest$` tokens are in
  108. ISO-8601 format and the target system must understand this format.
  109. * If the job performs an analysis against nested JSON fields, the tokens for
  110. string substitution can refer to these fields using dot notation. For example,
  111. `$cpu.total$`.
  112. * {es} source data mappings might make it difficult for the query string to work.
  113. Test the custom URL before saving the job configuration to check that it works
  114. as expected, particularly when using string substitution.
  115. ===============================