Skip to content

Commit

Permalink
Fix doc build issues happening in linux/memory (#27381) (#28218)
Browse files Browse the repository at this point in the history
* fix doc build issues

* add changelog

* move tests to linux-only

(cherry picked from commit b906aab)

Co-authored-by: Alex K <[email protected]>
  • Loading branch information
mergify[bot] and fearful-symmetry authored Oct 1, 2021
1 parent d27aa4b commit 111709b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 64 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ https:/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- [Metricbeat][Kubernetes] Change cluster_ip field from ip to keyword. {pull}20571[20571]
- The `o365input` and `o365` module now recover from an authentication problem or other fatal errors, instead of terminating. {pull}21258[21258]
- Beats dashboards use custom index when `setup.dashboards.index` is set. {issue}21232[21232] {pull}27901[27901]
- Rename cloud.provider `az` value to `azure` inside the add_cloud_metadata processor. {pull}20689[20689]
- Add missing country_name geo field in `add_host_metadata` and `add_observer_metadata` processors. {issue}20796[20796] {pull}20811[20811]
- [Autodiscover] Handle input-not-finished errors in config reload. {pull}20915[20915]
- Explicitly detect missing variables in autodiscover configuration, log them at the debug level. {issue}20568[20568] {pull}20898[20898]
- Fix `libbeat.output.write.bytes` and `libbeat.output.read.bytes` metrics of the Elasticsearch output. {issue}20752[20752] {pull}21197[21197]
- Orderly close processors when processing pipelines are not needed anymore to release their resources. {pull}16349[16349]
- Fix memory leak and events duplication in docker autodiscover and add_docker_metadata. {pull}21851[21851]
- Fixed documentation for commands in beats dev guide {pull}22194[22194]
- Fix parsing of expired licences. {issue}21112[21112] {pull}22180[22180]
- Fix duplicated pod events in kubernetes autodiscover for pods with init or ephemeral containers. {pull}22438[22438]
- Fix FileVersion contained in Windows exe files. {pull}22581[22581]
- Fix index template loading when the new index format is selected. {issue}22482[22482] {pull}22682[22682]
- Periodic metrics in logs will now report `libbeat.output.events.active` and `beat.memstats.rss`
as gauges (rather than counters). {pull}22877[22877]
- Improve `perfmon` metricset performance. {pull}26886[26886]
- Preserve annotations in a kubernetes namespace metadata {pull}27045[27045]
- Allow conditional processing in `decode_xml` and `decode_xml_wineventlog`. {pull}27159[27159]
- Fix build constraint that caused issues with doc builds. {pull}27381[27381]

*Auditbeat*

Expand Down
79 changes: 79 additions & 0 deletions metricbeat/internal/metrics/memory/memory_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// 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.

package memory

import (
"bufio"
"bytes"
"io"
"io/ioutil"
"path/filepath"
"strconv"
"strings"

"github.com/pkg/errors"
)

// ParseMeminfo parses the contents of /proc/meminfo into a hashmap
func ParseMeminfo(rootfs string) (map[string]uint64, error) {
table := map[string]uint64{}

meminfoPath := filepath.Join(rootfs, "/proc/meminfo")
err := readFile(meminfoPath, func(line string) bool {
fields := strings.Split(line, ":")

if len(fields) != 2 {
return true // skip on errors
}

valueUnit := strings.Fields(fields[1])
value, err := strconv.ParseUint(valueUnit[0], 10, 64)
if err != nil {
return true // skip on errors
}

if len(valueUnit) > 1 && valueUnit[1] == "kB" {
value *= 1024
}
table[fields[0]] = value

return true
})
return table, err
}

func readFile(file string, handler func(string) bool) error {
contents, err := ioutil.ReadFile(file)
if err != nil {
return errors.Wrapf(err, "error reading file %s", file)
}

reader := bufio.NewReader(bytes.NewBuffer(contents))

for {
line, _, err := reader.ReadLine()
if err == io.EOF {
break
}
if !handler(string(line)) {
break
}
}

return nil
}
57 changes: 0 additions & 57 deletions metricbeat/internal/metrics/memory/memory_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
package memory

import (
"bufio"
"bytes"
"io"
"io/ioutil"
"path/filepath"
"strconv"
"strings"

"github.com/pkg/errors"

"github.com/elastic/beats/v7/libbeat/opt"
Expand Down Expand Up @@ -92,52 +84,3 @@ func get(rootfs string) (Memory, error) {
return memData, nil

}

// ParseMeminfo parses the contents of /proc/meminfo into a hashmap
func ParseMeminfo(rootfs string) (map[string]uint64, error) {
table := map[string]uint64{}

meminfoPath := filepath.Join(rootfs, "/proc/meminfo")
err := readFile(meminfoPath, func(line string) bool {
fields := strings.Split(line, ":")

if len(fields) != 2 {
return true // skip on errors
}

valueUnit := strings.Fields(fields[1])
value, err := strconv.ParseUint(valueUnit[0], 10, 64)
if err != nil {
return true // skip on errors
}

if len(valueUnit) > 1 && valueUnit[1] == "kB" {
value *= 1024
}
table[fields[0]] = value

return true
})
return table, err
}

func readFile(file string, handler func(string) bool) error {
contents, err := ioutil.ReadFile(file)
if err != nil {
return errors.Wrapf(err, "error reading file %s", file)
}

reader := bufio.NewReader(bytes.NewBuffer(contents))

for {
line, _, err := reader.ReadLine()
if err == io.EOF {
break
}
if !handler(string(line)) {
break
}
}

return nil
}
4 changes: 1 addition & 3 deletions metricbeat/module/linux/memory/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// specific language governing permissions and limitations
// under the License.

// +build linux

package memory

import (
Expand Down Expand Up @@ -139,7 +137,7 @@ func GetVMStat() (*sysinfotypes.VMStatInfo, error) {
}
vmstatHandle, ok := h.(sysinfotypes.VMStat)
if !ok {
return nil, errors.Wrap(err, "VMStat not available for platform")
return nil, errors.New("VMStat not available for platform")
}
info, err := vmstatHandle.VMStat()
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions metricbeat/module/linux/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// specific language governing permissions and limitations
// under the License.

// +build linux

package memory

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// specific language governing permissions and limitations
// under the License.

// +build linux

package memory

import (
Expand Down

0 comments on commit 111709b

Please sign in to comment.