-
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
Changes from 2 commits
d885578
873c3fd
4cb337f
672ee5e
bf166b6
dcfce4d
ee7a963
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// 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) { | ||
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", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
m := makeClusterToPipelinesMap(pipelines, "prod_cluster_id") | ||
require.Len(t, m, 1) | ||
for clusterID, pipelines := range m { | ||
require.Equal(t, "prod_cluster_id", clusterID) | ||
require.Len(t, pipelines, 1) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,26 +213,21 @@ func makeClusterToPipelinesMap(pipelines []PipelineStats, overrideClusterUUID st | |
var clusterToPipelinesMap map[string][]PipelineStats | ||
clusterToPipelinesMap = make(map[string][]PipelineStats) | ||
|
||
if overrideClusterUUID != "" { | ||
clusterToPipelinesMap[overrideClusterUUID] = pipelines | ||
return clusterToPipelinesMap | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this section because it's also incorrect. We shouldn't be using the override cluster UUID, if set, for all pipelines so broadly. Instead we should figure out (as we do further below) the cluster UUIDs appropriate for each pipeline and build the cluster UUID => pipelines map that way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is still a change in semantics and maybe a bc breaking change. Before this change all pipelines have had been associated with Instead of removing this line, how about printing a deprecation warning if this setting is configured and introduce an a default cluster uuid setting that matches the new semantics? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, looking at where the value of Reading the documentation for that setting:
This makes me think, if this setting is set and therefore So I'm going to revert this change and, in fact, add a similar code block in the |
||
for _, pipeline := range pipelines { | ||
var clusterUUIDs []string | ||
clusterUUIDs := make(map[string]struct{}, 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is The overall data expension starts by converting the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed the code to use
I think it's because I'm not finding the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do the conversion here. |
||
for _, vertex := range pipeline.Vertices { | ||
clusterUUID := logstash.GetVertexClusterUUID(vertex, overrideClusterUUID) | ||
if clusterUUID != "" { | ||
clusterUUIDs = append(clusterUUIDs, clusterUUID) | ||
clusterUUIDs[clusterUUID] = struct{}{} | ||
} | ||
} | ||
|
||
// If no cluster UUID was found in this pipeline, assign it a blank one | ||
if len(clusterUUIDs) == 0 { | ||
clusterUUIDs = []string{""} | ||
clusterUUIDs[""] = struct{}{} | ||
} | ||
|
||
for _, clusterUUID := range clusterUUIDs { | ||
for clusterUUID, _ := range clusterUUIDs { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit |
||
clusterPipelines := clusterToPipelinesMap[clusterUUID] | ||
if clusterPipelines == nil { | ||
clusterToPipelinesMap[clusterUUID] = []PipelineStats{} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// 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_stats | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMakeClusterToPipelinesMap(t *testing.T) { | ||
pipelines := []PipelineStats{ | ||
{ | ||
ID: "test_pipeline", | ||
Vertices: []map[string]interface{}{ | ||
{ | ||
"id": "vertex_1", | ||
}, | ||
{ | ||
"id": "vertex_2", | ||
}, | ||
{ | ||
"id": "vertex_3", | ||
}, | ||
}, | ||
}, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this particular case able to reproduce the issue we have had? If not, we should add one. The expannsion into the cluster map is somewhat critical in order to produce correct docs, that show the correct association of configurations to single Elasticsearch clusters. Can we make this test more exhaustive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is the case that was problematic. Before this PR this case would've produced 3 I will expand this test to add a few more test cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added more test cases in 672ee5e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||
|
||
m := makeClusterToPipelinesMap(pipelines, "prod_cluster_id") | ||
require.Len(t, m, 1) | ||
for clusterID, pipelines := range m { | ||
require.Equal(t, "prod_cluster_id", clusterID) | ||
require.Len(t, pipelines, 1) | ||
} | ||
} |
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.
common.StringSet