Skip to content

Commit

Permalink
Report k8s pct metrics from enrichment process (#7677)
Browse files Browse the repository at this point in the history
Instead of doing it from the `state_container`. Problem with the
previous approach is that `state_container` metricset is not run in all
nodes, but from a single point. Making performance metrics not available
in all cases.

With this new approach, the enriching process will also collect
performance metrics, so they should be available everywhere where the
module is run.
  • Loading branch information
exekias authored and ruflin committed Jul 23, 2018
1 parent 9db7866 commit 425828a
Show file tree
Hide file tree
Showing 53 changed files with 17,363 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ https://github.com/elastic/beats/compare/v6.2.3...master[Check the HEAD diff]
- Fix Jolokia attribute mapping when using wildcards and MBean names with multiple properties. {pull}7321[7321]
- Do not report Metricbeat container host as hostname in Kubernetes deployment. {issue}7199[7199]
- Ensure metadata updates don't replace existing pod metrics. {pull}7573[7573]
- Fix kubernetes pct fields reporting. {pull}7677[7677]

*Packetbeat*

Expand Down
88 changes: 88 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,49 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--------------------------------------------------------------------
Dependency: github.com/gogo/protobuf
Revision: 636bf0302bc95575d69441b25a2603156ffdddf1
License type (autodetected): BSD-3-Clause
./metricbeat/vendor/github.com/gogo/protobuf/LICENSE:
--------------------------------------------------------------------
Protocol Buffers for Go with Gadgets

Copyright (c) 2013, The GoGo Authors. All rights reserved.
http://github.com/gogo/protobuf

Go support for Protocol Buffers - Google's data interchange format

Copyright 2010 The Go Authors. All rights reserved.
https://github.com/golang/protobuf

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------
Dependency: github.com/golang/protobuf
Revision: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef
Expand Down Expand Up @@ -1380,6 +1423,16 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------
Dependency: github.com/kubernetes/apimachinery
Version: kubernetes-1.11.1
Revision: 103fd098999dc9c0c88536f5c9ad2e5da39373ae
License type (autodetected): Apache-2.0
./metricbeat/vendor/github.com/kubernetes/apimachinery/LICENSE:
--------------------------------------------------------------------
Apache License 2.0


--------------------------------------------------------------------
Dependency: github.com/lib/pq
Revision: 2704adc878c21e1329f46f6e56a1c387d788ff94
Expand Down Expand Up @@ -2693,6 +2746,41 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------
Dependency: gopkg.in/inf.v0
Revision: d2d2541c53f18d2a059457998ce2876cc8e67cbf
License type (autodetected): BSD-3-Clause
./metricbeat/vendor/gopkg.in/inf.v0/LICENSE:
--------------------------------------------------------------------
Copyright (c) 2012 Péter Surányi. Portions Copyright (c) 2009 The Go
Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------
Dependency: gopkg.in/mgo.v2
Revision: 3f83fa5005286a7fe593b055f0d7771a7dce4655
Expand Down
2 changes: 0 additions & 2 deletions metricbeat/module/kubernetes/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# - container
# - volume
period: 10s
hosts: ["localhost:10255"]

hosts: ["localhost:10250"]
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
ssl.certificate_authorities:
Expand Down
38 changes: 36 additions & 2 deletions metricbeat/module/kubernetes/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"sync"
"time"

"github.com/kubernetes/apimachinery/pkg/api/resource"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/kubernetes"
"github.com/elastic/beats/libbeat/logp"
Expand Down Expand Up @@ -95,10 +97,10 @@ func GetWatcher(base mb.BaseMetricSet, resource kubernetes.Resource, nodeScope b
// NewResourceMetadataEnricher returns an Enricher configured for kubernetes resource events
func NewResourceMetadataEnricher(
base mb.BaseMetricSet,
resource kubernetes.Resource,
res kubernetes.Resource,
nodeScope bool) Enricher {

watcher, err := GetWatcher(base, resource, nodeScope)
watcher, err := GetWatcher(base, res, nodeScope)
if err != nil {
logp.Err("Error initializing Kubernetes metadata enricher: %s", err)
return &nilEnricher{}
Expand All @@ -123,6 +125,23 @@ func NewResourceMetadataEnricher(
switch r := r.(type) {
case *kubernetes.Pod:
m[id] = metaGen.PodMetadata(r)

case *kubernetes.Node:
// Report node allocatable resources to PerfMetrics cache
name := r.GetMetadata().GetName()
if cpu, ok := r.GetStatus().GetCapacity()["cpu"]; ok {
if q, err := resource.ParseQuantity(cpu.GetString_()); err == nil {
PerfMetrics.NodeCoresAllocatable.Set(name, float64(q.MilliValue())/1000)
}
}
if memory, ok := r.GetStatus().GetCapacity()["memory"]; ok {
if q, err := resource.ParseQuantity(memory.GetString_()); err == nil {
PerfMetrics.NodeMemAllocatable.Set(name, float64(q.Value()))
}
}

m[id] = metaGen.ResourceMetadata(r)

default:
m[id] = metaGen.ResourceMetadata(r)
}
Expand Down Expand Up @@ -169,7 +188,22 @@ func NewContainerMetadataEnricher(
func(m map[string]common.MapStr, r kubernetes.Resource) {
pod := r.(*kubernetes.Pod)
meta := metaGen.PodMetadata(pod)

for _, container := range append(pod.GetSpec().GetContainers(), pod.GetSpec().GetInitContainers()...) {
cuid := ContainerUID(pod.GetMetadata().GetNamespace(), r.GetMetadata().GetName(), container.GetName())

// Report container limits to PerfMetrics cache
if cpu, ok := container.GetResources().GetLimits()["cpu"]; ok {
if q, err := resource.ParseQuantity(cpu.GetString_()); err == nil {
PerfMetrics.ContainerCoresLimit.Set(cuid, float64(q.MilliValue())/1000)
}
}
if memory, ok := container.GetResources().GetLimits()["memory"]; ok {
if q, err := resource.ParseQuantity(memory.GetString_()); err == nil {
PerfMetrics.ContainerMemLimit.Set(cuid, float64(q.Value()))
}
}

id := join(r.GetMetadata().GetNamespace(), r.GetMetadata().GetName(), container.GetName())
m[id] = meta
}
Expand Down
2 changes: 0 additions & 2 deletions metricbeat/modules.d/kubernetes.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# - container
# - volume
period: 10s
hosts: ["localhost:10255"]

hosts: ["localhost:10250"]
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
ssl.certificate_authorities:
Expand Down
36 changes: 36 additions & 0 deletions metricbeat/vendor/github.com/gogo/protobuf/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions metricbeat/vendor/github.com/gogo/protobuf/proto/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 425828a

Please sign in to comment.