-
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
Kubernetes state_* metricsets are ignoring namespace #6281 #6294
Changes from all commits
16d57a1
265b892
6a46aba
1f7be96
99eb905
7e06452
77d182c
17f1ef4
5a397e5
c14d1bc
fe25b1f
f417b81
b514a50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,35 +44,76 @@ func TestEventMapping(t *testing.T) { | |
events, err := f.Fetch() | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, 4, len(events), "Wrong number of returned events") | ||
|
||
testCases := map[string]interface{}{ | ||
"_module.namespace": "default", | ||
|
||
"name": "jumpy-owl-redis", | ||
"paused": false, | ||
|
||
"replicas.available": 0, | ||
"replicas.desired": 1, | ||
"replicas.unavailable": 1, | ||
"replicas.updated": 1, | ||
} | ||
assert.Equal(t, 5, len(events), "Wrong number of returned events") | ||
|
||
testCases := testCases() | ||
for _, event := range events { | ||
name, err := event.GetValue("name") | ||
if err == nil && name == "jumpy-owl-redis" { | ||
for k, v := range testCases { | ||
testValue(t, event, k, v) | ||
if err == nil { | ||
namespace, err := event.GetValue("_module.namespace") | ||
if err == nil { | ||
eventKey := namespace.(string) + "@" + name.(string) | ||
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. And I assume this one means an 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 @ works in the same way, it's used to fetch the correct test case from here: https://github.com/elastic/beats/pull/6294/files/b514a509da8360ab225e85eb73df79468057cbd7#diff-2b3ff3319749ebeecd269e64715d1969R80 The @ is not in the final event |
||
oneTestCase, oneTestCaseFound := testCases[eventKey] | ||
if oneTestCaseFound { | ||
for k, v := range oneTestCase { | ||
testValue(eventKey, t, event, k, v) | ||
} | ||
delete(testCases, eventKey) | ||
} | ||
} | ||
return | ||
} | ||
} | ||
|
||
t.Error("Test reference event not found") | ||
if len(testCases) > 0 { | ||
t.Errorf("Test reference events not found: %v, \n\ngot: %v", testCases, events) | ||
} | ||
} | ||
|
||
func testValue(t *testing.T, event common.MapStr, field string, expected interface{}) { | ||
func testValue(eventKey string, t *testing.T, event common.MapStr, field string, expected interface{}) { | ||
data, err := event.GetValue(field) | ||
assert.NoError(t, err, "Could not read field "+field) | ||
assert.EqualValues(t, expected, data, "Wrong value for field "+field) | ||
assert.NoError(t, err, eventKey+": Could not read field "+field) | ||
assert.EqualValues(t, expected, data, eventKey+": Wrong value for field "+field) | ||
} | ||
|
||
// Test cases built to match 3 examples in 'module/kubernetes/_meta/test/kube-state-metrics'. | ||
// In particular, test same named deployments in different namespaces | ||
func testCases() map[string]map[string]interface{} { | ||
return map[string]map[string]interface{}{ | ||
"default@jumpy-owl-redis": { | ||
"_namespace": "deployment", | ||
"_module.namespace": "default", | ||
|
||
"name": "jumpy-owl-redis", | ||
"paused": false, | ||
|
||
"replicas.available": 0, | ||
"replicas.desired": 1, | ||
"replicas.unavailable": 1, | ||
"replicas.updated": 1, | ||
}, | ||
"test@jumpy-owl-redis": { | ||
"_namespace": "deployment", | ||
"_module.namespace": "test", | ||
|
||
"name": "jumpy-owl-redis", | ||
"paused": true, | ||
|
||
"replicas.available": 6, | ||
"replicas.desired": 2, | ||
"replicas.unavailable": 7, | ||
"replicas.updated": 8, | ||
}, | ||
"kube-system@tiller-deploy": { | ||
"_namespace": "deployment", | ||
"_module.namespace": "kube-system", | ||
|
||
"name": "tiller-deploy", | ||
"paused": false, | ||
|
||
"replicas.available": 1, | ||
"replicas.desired": 1, | ||
"replicas.unavailable": 0, | ||
"replicas.updated": 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.
@exekias Does this mean we have
::
in the field key?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.
No, this is a key in the
eventMap
, we use it to correlate all different metrics into a single event, then we ship events, forgetting about the keys in the mapThere 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.
got it, thanks.