Skip to content

Commit

Permalink
Install data stream template for Kibana reporting
Browse files Browse the repository at this point in the history
Kibana reporting is migrating to a data stream. This commit installs an index template for the
hidden data stream, as well as updating the `kibana_system` role to allow accessing the data.

Relates to elastic/kibana#161606
  • Loading branch information
dakrone committed Jul 18, 2023
1 parent 08f6275 commit 6c8c65e
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,7 @@ protected static boolean isXPackTemplate(String name) {
case "data-streams-mappings":
case "ecs@dynamic_templates":
case "search-acl-filter":
case ".kibana-reporting":
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static RoleDescriptor kibanaSystem(String name) {
new RoleDescriptor.IndicesPrivileges[] {
// System indices defined in KibanaPlugin
RoleDescriptor.IndicesPrivileges.builder()
.indices(".kibana*", ".reporting-*")
.indices(".kibana*", ".reporting-*", ".kibana-reporting*")
.privileges("all")
.allowRestrictedIndices(true)
.build(),
Expand Down
168 changes: 168 additions & 0 deletions x-pack/plugin/core/src/main/resources/kibana-reporting-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"index_patterns": [".kibana-reporting*"],
"priority": 100,
"data_stream": {
"hidden": true
},
"allow_auto_create": true,
"template": {
"settings": {
"number_of_shards": 1,
"auto_expand_replicas": "0-1"
},
"mappings": {
"properties": {
"meta": {
"properties": {
"objectType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"layout": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"isDeprecated": {
"type": "boolean"
}
}
},
"migration_version": {
"type": "keyword"
},
"jobtype": {
"type": "keyword"
},
"payload": {
"type": "object",
"enabled": false
},
"priority": {
"type": "byte"
},
"timeout": {
"type": "long"
},
"process_expiration": {
"type": "date"
},
"created_by": {
"type": "keyword"
},
"created_at": {
"type": "date"
},
"started_at": {
"type": "date"
},
"completed_at": {
"type": "date"
},
"attempts": {
"type": "short"
},
"max_attempts": {
"type": "short"
},
"kibana_name": {
"type": "keyword"
},
"kibana_id": {
"type": "keyword"
},
"status": {
"type": "keyword"
},
"parent_id": {
"type": "keyword"
},
"output": {
"type": "object",
"properties": {
"error_code": {
"type": "keyword"
},
"chunk": {
"type": "long"
},
"content_type": {
"type": "keyword"
},
"size": {
"type": "long"
},
"content": {
"type": "object",
"enabled": false
}
}
},
"metrics": {
"type": "object",
"properties": {
"csv": {
"type": "object",
"properties": {
"rows": {
"type": "long"
}
}
},
"pdf": {
"type": "object",
"properties": {
"pages": {
"type": "long"
},
"cpu": {
"type": "double"
},
"cpuInPercentage": {
"type": "double"
},
"memory": {
"type": "long"
},
"memoryInMegabytes": {
"type": "double"
}
}
},
"png": {
"type": "object",
"properties": {
"cpu": {
"type": "double"
},
"cpuInPercentage": {
"type": "double"
},
"memory": {
"type": "long"
},
"memoryInMegabytes": {
"type": "double"
}
}
}
}
}
}
}
},
"_meta": {
"description": "default kibana reporting template installed by elasticsearch",
"managed": true
},
"version": ${xpack.stack.template.version}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ setup:
indices.get_index_template:
name: metrics

- do:
indices.get_index_template:
name: synthetics

- do:
indices.get_index_template:
name: .kibana-reporting

---
"Test logs index auto creation":
- do:
Expand Down Expand Up @@ -185,6 +193,42 @@ setup:
indices.delete_data_stream:
name: synthetics-foo-bar

---
"Test kibana reporting index auto creation":
- do:
index:
index: .kibana-reporting-foo
body:
"@timestamp": "2020-01-01"
jobtype: "thing"

- do:
indices.get_data_stream:
name: .kibana-reporting-foo

- match: { data_streams.0.name: .kibana-reporting-foo }
- match: { data_streams.0.hidden: true }
- match: { data_streams.0.timestamp_field.name: '@timestamp' }
- match: { data_streams.0.generation: 1 }
- length: { data_streams.0.indices: 1 }
- match: { data_streams.0.indices.0.index_name: '/\.ds-.kibana-reporting-foo-(\d{4}\.\d{2}\.\d{2}-)?000001/' }

- set: { data_streams.0.indices.0.index_name: idx0name }

- do:
indices.get:
index: $idx0name

- is_true: .$idx0name.settings
- is_true: .$idx0name.mappings
- match: { .$idx0name.mappings.properties.meta.properties.objectType.type: "text" }
- match: { .$idx0name.mappings.properties.meta.properties.layout.type: "text" }
- match: { .$idx0name.data_stream: ".kibana-reporting-foo" }

- do:
indices.delete_data_stream:
name: .kibana-reporting-foo

---
"Test wrong data_stream type":

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public class StackTemplateRegistry extends IndexTemplateRegistry {
public static final String SYNTHETICS_ILM_POLICY_NAME = "synthetics";
public static final String SYNTHETICS_INDEX_TEMPLATE_NAME = "synthetics";

///////////////////////////////////
// Kibana reporting template
///////////////////////////////////
public static final String KIBANA_REPORTING_INDEX_TEMPLATE_NAME = ".kibana-reporting";

public StackTemplateRegistry(
Settings nodeSettings,
ClusterService clusterService,
Expand Down Expand Up @@ -224,7 +229,13 @@ protected Map<String, ComponentTemplate> getComponentTemplateConfigs() {
private static final Map<String, ComposableIndexTemplate> COMPOSABLE_INDEX_TEMPLATE_CONFIGS = parseComposableTemplates(
new IndexTemplateConfig(LOGS_INDEX_TEMPLATE_NAME, "/logs-template.json", REGISTRY_VERSION, TEMPLATE_VERSION_VARIABLE),
new IndexTemplateConfig(METRICS_INDEX_TEMPLATE_NAME, "/metrics-template.json", REGISTRY_VERSION, TEMPLATE_VERSION_VARIABLE),
new IndexTemplateConfig(SYNTHETICS_INDEX_TEMPLATE_NAME, "/synthetics-template.json", REGISTRY_VERSION, TEMPLATE_VERSION_VARIABLE)
new IndexTemplateConfig(SYNTHETICS_INDEX_TEMPLATE_NAME, "/synthetics-template.json", REGISTRY_VERSION, TEMPLATE_VERSION_VARIABLE),
new IndexTemplateConfig(
KIBANA_REPORTING_INDEX_TEMPLATE_NAME,
"/kibana-reporting-template.json",
REGISTRY_VERSION,
TEMPLATE_VERSION_VARIABLE
)
);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public void testPolicyAlreadyExists() {
if (action instanceof PutComponentTemplateAction) {
// Ignore this, it's verified in another test
return AcknowledgedResponse.TRUE;
} else if (action instanceof PutComposableIndexTemplateAction) {
// Ignore this, it's verified in another test
return AcknowledgedResponse.TRUE;
} else if (action instanceof PutLifecycleAction) {
fail("if the policy already exists it should not be re-put");
} else {
Expand Down Expand Up @@ -255,6 +258,9 @@ public void testPolicyAlreadyExistsButDiffers() throws IOException {
if (action instanceof PutComponentTemplateAction) {
// Ignore this, it's verified in another test
return AcknowledgedResponse.TRUE;
} else if (action instanceof PutComposableIndexTemplateAction) {
// Ignore this, it's verified in another test
return AcknowledgedResponse.TRUE;
} else if (action instanceof PutLifecycleAction) {
fail("if the policy already exists it should not be re-put");
} else {
Expand Down

0 comments on commit 6c8c65e

Please sign in to comment.