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

Check dashboards index pattern #13303

Merged
merged 8 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Syslog input will now omit the `process` object from events if it is empty. {pull}12700[12700]
- Fix multiline pattern in Postgres which was too permissive {issue}12078[12078] {pull}13069[13069]
- Allow path variables to be used in files loaded from modules.d. {issue}13184[13184]
- Fix incorrect references to index patterns in AWS and CoreDNS dashboards. {pull}13303[13303]

*Heartbeat*

Expand Down Expand Up @@ -164,7 +165,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix incoherent behaviour in redis key metricset when keyspace is specified both in host URL and key pattern {pull}12913[12913]
- Fix connections leak in redis module {pull}12914[12914] {pull}12950[12950]
- Fix wrong uptime reporting by system/uptime metricset under Windows. {pull}12915[12915]
- Print errors that were being omitted in vSphere metricsets {pull}12816[12816]
- Print errors that were being omitted in vSphere metricsets. {pull}12816[12816]
- Fix redis key metricset dashboard references to index pattern. {pull}13303[13303]

*Packetbeat*

Expand Down
46 changes: 44 additions & 2 deletions dev-tools/mage/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,25 @@ type Dashboard struct {
type dashboardObject struct {
Type string `json:"type"`
Attributes struct {
Description string `json:"description"`
Title string `json:"title"`
Description string `json:"description"`
Title string `json:"title"`
KibanaSavedObjectMeta *struct {
SearchSourceJSON struct {
Index string `json:"index"`
} `json:"searchSourceJSON,omitempty"`
} `json:"kibanaSavedObjectMeta"`
VisState *struct {
Params struct {
Controls []struct {
IndexPattern string
} `json:"controls"`
} `json:"params"`
} `json:"visState,omitempty"`
} `json:"attributes"`
References []struct {
Type string `json:"type"`
ID string `json:"id"`
} `json:"references"`
}

var (
Expand All @@ -271,6 +287,11 @@ func (d *Dashboard) CheckFormat(module string) []error {
return errors.Wrapf(err, "expected title with format 'Some title [%s Module]', found '%s'", strings.Title(BeatName), o.Attributes.Title)
}
}

expectedIndexPattern := strings.ToLower(BeatName) + "-*"
if err := checkDashboardIndexPattern(expectedIndexPattern, o); err != nil {
return errors.Wrapf(err, "expected index pattern reference '%s'", expectedIndexPattern)
}
return nil
}
var errs []error
Expand Down Expand Up @@ -301,3 +322,24 @@ func checkTitle(re *regexp.Regexp, title string, module string) error {
}
return nil
}

func checkDashboardIndexPattern(expectedIndex string, o *dashboardObject) error {
if objectMeta := o.Attributes.KibanaSavedObjectMeta; objectMeta != nil {
if index := objectMeta.SearchSourceJSON.Index; index != "" && index != expectedIndex {
return errors.Errorf("unexpected index pattern reference found in object meta: %s", index)
}
}
if visState := o.Attributes.VisState; visState != nil {
for _, control := range visState.Params.Controls {
if index := control.IndexPattern; index != "" && index != expectedIndex {
kaiyan-sheng marked this conversation as resolved.
Show resolved Hide resolved
return errors.Errorf("unexpected index pattern reference found in visualization state: %s", index)
}
}
}
for _, reference := range o.References {
if reference.Type == "index-pattern" && reference.ID != expectedIndex {
return errors.Errorf("unexpected reference to index pattern %s", reference.ID)
}
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
"fieldName": "redis.keyspace.id",
"id": "1545388837304",
"indexPattern": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"indexPattern": "metricbeat-*",
"label": "Keyspace",
"options": {
"dynamicOptions": true,
Expand Down Expand Up @@ -61,7 +61,7 @@
"meta": {
"alias": null,
"disabled": false,
"index": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"index": "metricbeat-*",
"key": "redis.key.type",
"negate": false,
"params": {
Expand All @@ -81,7 +81,7 @@
}
}
],
"index": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"index": "metricbeat-*",
"query": {
"language": "kuery",
"query": ""
Expand Down Expand Up @@ -243,7 +243,7 @@
"kibanaSavedObjectMeta": {
"searchSourceJSON": {
"filter": [],
"index": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"index": "metricbeat-*",
"query": {
"language": "kuery",
"query": ""
Expand Down Expand Up @@ -399,7 +399,7 @@
"meta": {
"alias": null,
"disabled": false,
"index": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"index": "metricbeat-*",
"key": "redis.key.type",
"negate": false,
"params": {
Expand All @@ -419,7 +419,7 @@
}
}
],
"index": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"index": "metricbeat-*",
"query": {
"language": "kuery",
"query": ""
Expand Down Expand Up @@ -570,7 +570,7 @@
"meta": {
"alias": null,
"disabled": false,
"index": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"index": "metricbeat-*",
"key": "redis.key.expire.ttl",
"negate": false,
"params": {
Expand All @@ -588,7 +588,7 @@
}
}
],
"index": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"index": "metricbeat-*",
"query": {
"language": "kuery",
"query": ""
Expand Down Expand Up @@ -758,7 +758,7 @@
"alias": null,
"controlledBy": "1545388837304",
"disabled": false,
"index": "bc2e8280-0509-11e9-9c60-d582a238e2c5",
"index": "metricbeat-*",
"key": "redis.keyspace.id",
"negate": false,
"params": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
},
"references": [
{
"id": "46074e60-babd-11e9-9f70-1f7bda85a5eb",
"id": "filebeat-*",
"name": "kibanaSavedObjectMeta.searchSourceJSON.index",
"type": "index-pattern"
}
Expand Down Expand Up @@ -401,12 +401,12 @@
},
"references": [
{
"id": "46074e60-babd-11e9-9f70-1f7bda85a5eb",
"id": "filebeat-*",
"name": "kibanaSavedObjectMeta.searchSourceJSON.index",
"type": "index-pattern"
},
{
"id": "46074e60-babd-11e9-9f70-1f7bda85a5eb",
"id": "filebeat-*",
"name": "kibanaSavedObjectMeta.searchSourceJSON.filter[0].meta.index",
"type": "index-pattern"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
},
"references": [
{
"id": "8d890080-413c-11e9-8548-ab7fbe04f038",
"id": "filebeat-*",
"name": "kibanaSavedObjectMeta.searchSourceJSON.index",
"type": "index-pattern"
}
Expand Down Expand Up @@ -245,7 +245,7 @@
},
"references": [
{
"id": "8d890080-413c-11e9-8548-ab7fbe04f038",
"id": "filebeat-*",
"name": "kibanaSavedObjectMeta.searchSourceJSON.index",
"type": "index-pattern"
}
Expand Down Expand Up @@ -344,7 +344,7 @@
},
"references": [
{
"id": "8d890080-413c-11e9-8548-ab7fbe04f038",
"id": "filebeat-*",
"name": "kibanaSavedObjectMeta.searchSourceJSON.index",
"type": "index-pattern"
}
Expand Down