Skip to content

Commit

Permalink
Merge branch 'prometheus:master' into add-drm-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jritter authored Sep 11, 2021
2 parents 53c23cf + 21d221e commit 60d40ca
Show file tree
Hide file tree
Showing 56 changed files with 2,519 additions and 283 deletions.
63 changes: 36 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
---
version: 2.1

commands:
default:
steps:
- run: make style check_license test lint
no-test:
jobs:
lint:
docker:
- image: cimg/go:1.16
steps:
- run: make style check_license lint
- checkout
- run: make check_license
- run: ./scripts/check_build_tags.sh
- run: make fixtures
- run: make update_fixtures
- run: git diff --exit-code

jobs:
test:
parameters:
command:
type: string
go_version:
type: string
os:
type: string
run_test:
type: boolean
default: true
docker:
- image: circleci/golang:<< parameters.go_version >>
environment:
GOOS: "<< parameters.os >>"
working_directory: /go/src/github.com/prometheus/procfs
steps:
- checkout
- << parameters.command >>
- run: make style lint
- when:
condition: << parameters.run_test >>
steps:
- run: make test

codespell:
docker:
Expand All @@ -40,24 +47,26 @@ workflows:
version: 2
procfs:
jobs:
- lint
- test:
command: default
name: linux-1-15
os: linux
go_version: "1.15"
- test:
command: default
name: linux-1-14
name: test-linux
os: linux
go_version: "1.14"
- test:
command: no-test
name: windows-1-15
os: windows
go_version: "1.15"
matrix:
parameters:
go_version:
- "1.13"
- "1.14"
- "1.15"
- "1.16"
- test:
command: no-test
name: windows-1-14
name: test-windows
os: windows
go_version: "1.14"
run_test: false
matrix:
parameters:
go_version:
- "1.13"
- "1.14"
- "1.15"
- "1.16"
- codespell
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ include Makefile.common
./ttar -C $(dir $*) -x -f $*.ttar
touch $@

fixtures: fixtures/.unpacked

update_fixtures:
rm -vf fixtures/.unpacked
./ttar -c -f fixtures.ttar fixtures/
Expand Down
15 changes: 12 additions & 3 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ ifneq ($(shell which gotestsum),)
endif
endif

PROMU_VERSION ?= 0.7.0
PROMU_VERSION ?= 0.12.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz

GOLANGCI_LINT :=
GOLANGCI_LINT_OPTS ?=
GOLANGCI_LINT_VERSION ?= v1.18.0
GOLANGCI_LINT_VERSION ?= v1.39.0
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
# windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
Expand Down Expand Up @@ -118,7 +118,7 @@ endif
%: common-% ;

.PHONY: common-all
common-all: precheck style check_license lint unused build test
common-all: precheck style check_license lint yamllint unused build test

.PHONY: common-style
common-style:
Expand Down Expand Up @@ -198,6 +198,15 @@ else
endif
endif

.PHONY: common-yamllint
common-yamllint:
@echo ">> running yamllint on all YAML files in the repository"
ifeq (, $(shell which yamllint))
@echo "yamllint not installed so skipping"
else
yamllint .
endif

# For backward-compatibility.
.PHONY: common-staticcheck
common-staticcheck: lint
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metrics from the pseudo-filesystems /proc and /sys.
*WARNING*: This package is a work in progress. Its API may still break in
backwards-incompatible ways without warnings. Use it at your own risk.

[![GoDoc](https://godoc.org/github.com/prometheus/procfs?status.png)](https://godoc.org/github.com/prometheus/procfs)
[![Build Status](https://travis-ci.org/prometheus/procfs.svg?branch=master)](https://travis-ci.org/prometheus/procfs)
[![Go Reference](https://pkg.go.dev/badge/github.com/prometheus/procfs.svg)](https://pkg.go.dev/github.com/prometheus/procfs)
[![CircleCI](https://circleci.com/gh/prometheus/procfs/tree/master.svg?style=svg)](https://circleci.com/gh/prometheus/procfs/tree/master)
[![Go Report Card](https://goreportcard.com/badge/github.com/prometheus/procfs)](https://goreportcard.com/report/github.com/prometheus/procfs)

## Usage
Expand Down
8 changes: 4 additions & 4 deletions blockdevice/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const (
procDiskstatsPath = "diskstats"
procDiskstatsFormat = "%d %d %s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
sysBlockPath = "block"
sysBlockStatFormat = "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
sysBlockStatFormat = "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"
sysBlockQueue = "queue"
)

Expand Down Expand Up @@ -274,9 +274,7 @@ func (fs FS) SysBlockDevices() ([]string, error) {
}
devices := []string{}
for _, deviceDir := range deviceDirs {
if deviceDir.IsDir() {
devices = append(devices, deviceDir.Name())
}
devices = append(devices, deviceDir.Name())
}
return devices, nil
}
Expand Down Expand Up @@ -306,6 +304,8 @@ func (fs FS) SysBlockDeviceStat(device string) (IOStats, int, error) {
&stat.DiscardMerges,
&stat.DiscardSectors,
&stat.DiscardTicks,
&stat.FlushRequestsCompleted,
&stat.TimeSpentFlushing,
)
// An io.EOF error is ignored because it just means we read fewer than the full 15 fields.
if err == io.EOF {
Expand Down
30 changes: 30 additions & 0 deletions cmdline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2021 The Prometheus Authors
// Licensed 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 procfs

import (
"strings"

"github.com/prometheus/procfs/internal/util"
)

// CmdLine returns the command line of the kernel.
func (fs FS) CmdLine() ([]string, error) {
data, err := util.ReadFileNoStat(fs.proc.Path("cmdline"))
if err != nil {
return nil, err
}

return strings.Fields(string(data)), nil
}
47 changes: 47 additions & 0 deletions cmdline_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2021 The Prometheus Authors
// Licensed 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 linux

package procfs

import (
"testing"

"github.com/google/go-cmp/cmp"
)

func TestCmdline(t *testing.T) {
fs, err := NewFS(procTestFixtures)
if err != nil {
t.Fatal(err)
}

got, err := fs.CmdLine()
if err != nil {
t.Fatal(err)
}

want := []string{
"BOOT_IMAGE=/vmlinuz-5.11.0-22-generic",
"root=UUID=456a0345-450d-4f7b-b7c9-43e3241d99ad",
"ro",
"quiet",
"splash",
"vt.handoff=7",
}

if diff := cmp.Diff(want, got); diff != "" {
t.Fatalf("unexpected CmdLine (-want +got):\n%s", diff)
}
}
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// log.Fatalf("could not get process: %s", err)
// }
//
// stat, err := p.NewStat()
// stat, err := p.Stat()
// if err != nil {
// log.Fatalf("could not get process stat: %s", err)
// }
Expand Down
Loading

0 comments on commit 60d40ca

Please sign in to comment.