-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fixing logic to keep list of unique cluster UUIDs #22808
Merged
ycombinator
merged 7 commits into
elastic:master
from
ycombinator:mon-ls-dup-cluster-uuid
Dec 1, 2020
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d885578
Fixing logic to keep list of unique cluster UUIDs
ycombinator 873c3fd
Adding CHANGELOG entry
ycombinator 4cb337f
Use common.StringSet
ycombinator 672ee5e
Adding more test cases
ycombinator bf166b6
Adding back logic to broadly override cluster UUID for all pipelines,…
ycombinator dcfce4d
Removing ToSlice()
ycombinator ee7a963
Fixing loop
ycombinator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,328 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
// +build !integration | ||
|
||
package node | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/beats/v7/metricbeat/module/logstash" | ||
) | ||
|
||
func TestMakeClusterToPipelinesMap(t *testing.T) { | ||
tests := map[string]struct { | ||
pipelines []logstash.PipelineState | ||
overrideClusterUUID string | ||
expectedMap map[string][]logstash.PipelineState | ||
}{ | ||
"no_vertex_cluster_id": { | ||
pipelines: []logstash.PipelineState{ | ||
{ | ||
ID: "test_pipeline", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1", | ||
}, | ||
{ | ||
"id": "vertex_2", | ||
}, | ||
{ | ||
"id": "vertex_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
overrideClusterUUID: "prod_cluster_id", | ||
expectedMap: map[string][]logstash.PipelineState{ | ||
"prod_cluster_id": { | ||
{ | ||
ID: "test_pipeline", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1", | ||
}, | ||
{ | ||
"id": "vertex_2", | ||
}, | ||
{ | ||
"id": "vertex_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"one_vertex_cluster_id": { | ||
pipelines: []logstash.PipelineState{ | ||
{ | ||
ID: "test_pipeline", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1", | ||
"cluster_uuid": "es_1", | ||
}, | ||
{ | ||
"id": "vertex_2", | ||
}, | ||
{ | ||
"id": "vertex_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
overrideClusterUUID: "prod_cluster_id", | ||
expectedMap: map[string][]logstash.PipelineState{ | ||
"prod_cluster_id": { | ||
{ | ||
ID: "test_pipeline", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1", | ||
"cluster_uuid": "es_1", | ||
}, | ||
{ | ||
"id": "vertex_2", | ||
}, | ||
{ | ||
"id": "vertex_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"two_pipelines": { | ||
pipelines: []logstash.PipelineState{ | ||
{ | ||
ID: "test_pipeline_1", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1_1", | ||
"cluster_uuid": "es_1", | ||
}, | ||
{ | ||
"id": "vertex_1_2", | ||
}, | ||
{ | ||
"id": "vertex_1_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ID: "test_pipeline_2", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_2_1", | ||
}, | ||
{ | ||
"id": "vertex_2_2", | ||
}, | ||
{ | ||
"id": "vertex_2_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
overrideClusterUUID: "prod_cluster_id", | ||
expectedMap: map[string][]logstash.PipelineState{ | ||
"prod_cluster_id": { | ||
{ | ||
ID: "test_pipeline_1", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1_1", | ||
"cluster_uuid": "es_1", | ||
}, | ||
{ | ||
"id": "vertex_1_2", | ||
}, | ||
{ | ||
"id": "vertex_1_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ID: "test_pipeline_2", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_2_1", | ||
}, | ||
{ | ||
"id": "vertex_2_2", | ||
}, | ||
{ | ||
"id": "vertex_2_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"no_override_cluster_id": { | ||
pipelines: []logstash.PipelineState{ | ||
{ | ||
ID: "test_pipeline_1", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1_1", | ||
"cluster_uuid": "es_1", | ||
}, | ||
{ | ||
"id": "vertex_1_2", | ||
"cluster_uuid": "es_2", | ||
}, | ||
{ | ||
"id": "vertex_1_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ID: "test_pipeline_2", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_2_1", | ||
}, | ||
{ | ||
"id": "vertex_2_2", | ||
}, | ||
{ | ||
"id": "vertex_2_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
overrideClusterUUID: "", | ||
expectedMap: map[string][]logstash.PipelineState{ | ||
"es_1": { | ||
{ | ||
ID: "test_pipeline_1", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1_1", | ||
"cluster_uuid": "es_1", | ||
}, | ||
{ | ||
"id": "vertex_1_2", | ||
"cluster_uuid": "es_2", | ||
}, | ||
{ | ||
"id": "vertex_1_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"es_2": { | ||
{ | ||
ID: "test_pipeline_1", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1_1", | ||
"cluster_uuid": "es_1", | ||
}, | ||
{ | ||
"id": "vertex_1_2", | ||
"cluster_uuid": "es_2", | ||
}, | ||
{ | ||
"id": "vertex_1_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"": { | ||
{ | ||
ID: "test_pipeline_2", | ||
Graph: &logstash.GraphContainer{ | ||
Graph: &logstash.Graph{ | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_2_1", | ||
}, | ||
{ | ||
"id": "vertex_2_2", | ||
}, | ||
{ | ||
"id": "vertex_2_3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
actualMap := makeClusterToPipelinesMap(test.pipelines, test.overrideClusterUUID) | ||
require.Equal(t, test.expectedMap, actualMap) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
ToSlice
is a little overkill here (it copies and sorts all strings). The StringSet is defined astype StringSet map[string]struct{}
and can be directly use with the range-clause.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in dcfce4d.