Skip to content

Commit

Permalink
Merge pull request #158 from maier/master
Browse files Browse the repository at this point in the history
v2.5.0
  • Loading branch information
maier authored Aug 11, 2022
2 parents 40e8466 + 5bb6c4a commit 5a93262
Show file tree
Hide file tree
Showing 31 changed files with 156 additions and 134 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# v2.5.0

* fix: prevent `/usr/lib/.build-id` links from being created
* fix: ioutil deprecation
* fix: G112 add ReadHeaderTimeout to http.Server
* fix: gofmt certain files due to comment format
* fix: struct alignment in some test files for generated test snippets
* fix: pass context to fetchPromMetrics
* build(deps): bump github.com/shirou/gopsutil/v3 from 3.22.1 to 3.22.7
* build(deps): bump github.com/circonus-labs/go-apiclient from 0.7.15 to 0.7.17
* build(deps): bump github.com/prometheus/common from 0.32.1 to 0.37.0
* build(deps): bump github.com/spf13/cobra from 1.3.0 to 1.5.0
* build(deps): bump github.com/spf13/viper from 1.10.1 to 1.12.0
* build(deps): bump github.com/hashicorp/go-retryablehttp from 0.7.0 to 0.7.1
* build(deps): bump github.com/rs/zerolog from 1.25.0 to 1.26.1
* fix: add `v` to version (changelog)
* upd: set prerelease false (goreleaser)

# v2.4.3

* fix: downgrade gopsutil v3.21.8 - build fail - see gopsutil PR 1142
Expand Down
1 change: 0 additions & 1 deletion api/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@

/*
Package api provides the definition of the agent API
*/
package api
4 changes: 2 additions & 2 deletions api/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package api
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
)
Expand All @@ -35,7 +35,7 @@ func (c *Client) get(ctx context.Context, reqpath string) ([]byte, error) {
}

defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("reading response: %w", err)
}
Expand Down
10 changes: 6 additions & 4 deletions api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ import (

// Metrics retrieves metrics from one or all plugins
// NOTE: because the API is using the regular agent URL - the
// agent will act as though any other client (e.g. a broker)
// were requesting metrics - it will *run* the plugin(s).
//
// agent will act as though any other client (e.g. a broker)
// were requesting metrics - it will *run* the plugin(s).
func (c *Client) Metrics(pluginID string) (*Metrics, error) {
return c.MetricsWithContext(context.Background(), pluginID)
}

// MetricsWithContext retrieves metrics from one or all plugins
// NOTE: because the API is using the regular agent URL - the
// agent will act as though any other client (e.g. a broker)
// were requesting metrics - it will *run* the plugin(s).
//
// agent will act as though any other client (e.g. a broker)
// were requesting metrics - it will *run* the plugin(s).
func (c *Client) MetricsWithContext(ctx context.Context, pluginID string) (*Metrics, error) {
pid := ""
if pluginID != "" {
Expand Down
4 changes: 2 additions & 2 deletions api/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
)
Expand Down Expand Up @@ -59,7 +59,7 @@ func (c *Client) WriteWithContext(ctx context.Context, groupID string, metrics *
default:
// extract any error message and return
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("reading response: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions api/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package api

import (
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -32,7 +32,7 @@ func TestWrite(t *testing.T) {
t.Log("\t", test.name)
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("expected no error, got (%s)", err)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/builtins/collector/linux/procfs/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package procfs
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -314,7 +313,7 @@ func (c *Disk) getSectorSize(dev string) uint64 {

c.logger.Debug().Str("fn", fn).Msg("checking for sector size")

data, err := ioutil.ReadFile(fn)
data, err := os.ReadFile(fn)
if err != nil {
c.logger.Debug().Err(err).Str("device", dev).Msg("reading block size, using default")
c.sectorSizeCache[dev] = c.sectorSizeDefault
Expand Down
8 changes: 4 additions & 4 deletions internal/builtins/collector/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (c *Prom) Collect(ctx context.Context) error {

for _, u := range c.urls {
c.logger.Debug().Str("id", u.ID).Str("url", u.URL).Msg("prom fetch request")
err := c.fetchPromMetrics(u, &metrics)
err := c.fetchPromMetrics(ctx, u, &metrics)
if err != nil {
c.logger.Error().Err(err).Interface("url", u).Msg("fetching prom metrics")
}
Expand All @@ -177,7 +177,7 @@ func (c *Prom) Collect(ctx context.Context) error {
return nil
}

func (c *Prom) fetchPromMetrics(u URLDef, metrics *cgm.Metrics) error {
func (c *Prom) fetchPromMetrics(pctx context.Context, u URLDef, metrics *cgm.Metrics) error {
req, err := http.NewRequest("GET", u.URL, nil)
if err != nil {
return fmt.Errorf("prepare reqeust: %w", err)
Expand All @@ -187,9 +187,9 @@ func (c *Prom) fetchPromMetrics(u URLDef, metrics *cgm.Metrics) error {
var cancel context.CancelFunc

if u.uttl > time.Duration(0) {
ctx, cancel = context.WithTimeout(context.Background(), u.uttl)
ctx, cancel = context.WithTimeout(pctx, u.uttl)
} else {
ctx, cancel = context.WithCancel(context.Background())
ctx, cancel = context.WithCancel(pctx)
}

req = req.WithContext(ctx)
Expand Down
10 changes: 5 additions & 5 deletions internal/check/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package check
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/circonus-labs/go-apiclient"
Expand All @@ -22,25 +22,25 @@ var (
)

func init() {
if data, err := ioutil.ReadFile("testdata/check1234.json"); err != nil {
if data, err := os.ReadFile("testdata/check1234.json"); err != nil {
panic(err)
} else if err := json.Unmarshal(data, &testCheck); err != nil {
panic(err)
}

if data, err := ioutil.ReadFile("testdata/checkbundle1234.json"); err != nil {
if data, err := os.ReadFile("testdata/checkbundle1234.json"); err != nil {
panic(err)
} else if err := json.Unmarshal(data, &testCheckBundle); err != nil {
panic(err)
}

if data, err := ioutil.ReadFile("testdata/broker1234.json"); err != nil {
if data, err := os.ReadFile("testdata/broker1234.json"); err != nil {
panic(err)
} else if err := json.Unmarshal(data, &testBroker); err != nil {
panic(err)
}

if data, err := ioutil.ReadFile("testdata/ca.crt"); err != nil {
if data, err := os.ReadFile("testdata/ca.crt"); err != nil {
panic(err)
} else {
cacert.Contents = string(data)
Expand Down
4 changes: 2 additions & 2 deletions internal/check/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"net/url"
"os"

"github.com/circonus-labs/circonus-agent/internal/config"
"github.com/spf13/viper"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (c *Check) fetchBrokerCA() ([]byte, error) {
// use local file if specified
file := viper.GetString(config.KeyReverseBrokerCAFile)
if file != "" {
cert, err := ioutil.ReadFile(file)
cert, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("read file: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/check/bundle/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bundle
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/circonus-labs/circonus-agent/internal/release"
Expand All @@ -24,7 +24,7 @@ var (

func init() {
{
data, err := ioutil.ReadFile("testdata/checkbundle1234.json")
data, err := os.ReadFile("testdata/checkbundle1234.json")
if err != nil {
panic(err)
}
Expand All @@ -38,13 +38,13 @@ func init() {
testCheckBundleAgent.Notes = &notes
}

if data, err := ioutil.ReadFile("testdata/broker1234.json"); err != nil {
if data, err := os.ReadFile("testdata/broker1234.json"); err != nil {
panic(err)
} else if err := json.Unmarshal(data, &testBroker); err != nil {
panic(err)
}

if data, err := ioutil.ReadFile("testdata/ca.crt"); err != nil {
if data, err := os.ReadFile("testdata/ca.crt"); err != nil {
panic(err)
} else {
cacert.Contents = string(data)
Expand Down
3 changes: 1 addition & 2 deletions internal/check/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package bundle
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"
Expand Down Expand Up @@ -589,7 +588,7 @@ type MetricFilterFile struct {
func (cb *Bundle) getMetricFilters() ([][]string, error) {
mff := viper.GetString(config.KeyCheckMetricFilterFile)
if mff != "" {
data, err := ioutil.ReadFile(mff)
data, err := os.ReadFile(mff)
if err != nil {
if !os.IsNotExist(err) {
return nil, fmt.Errorf("reading %s: %w", mff, err)
Expand Down
9 changes: 4 additions & 5 deletions internal/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -362,7 +361,7 @@ func (c *Check) FetchBrokerConfig() error {

func (c *Check) loadAPICAfile(file string) *x509.CertPool {
cp := x509.NewCertPool()
cert, err := ioutil.ReadFile(file)
cert, err := os.ReadFile(file)
if err != nil {
c.logger.Error().Err(err).Str("file", file).Msg("unable to load api ca file")
return nil
Expand All @@ -375,9 +374,9 @@ func (c *Check) loadAPICAfile(file string) *x509.CertPool {
}

// DeleteCheck will attempt to delete a check bundle created by the agent.
// 1. The `etc/` directory must be writeable by the user running the agent.
// 2. The agent, when creating a check, will save the check object to `etc/check_bundle.json`.
// 3. The agent, when --check-delete is passed, will attempt to read this file and delete the check bundle.
// 1. The `etc/` directory must be writeable by the user running the agent.
// 2. The agent, when creating a check, will save the check object to `etc/check_bundle.json`.
// 3. The agent, when --check-delete is passed, will attempt to read this file and delete the check bundle.
func (c *Check) DeleteCheck() error {

bundleFile := defaults.CheckBundleFile
Expand Down
8 changes: 4 additions & 4 deletions internal/check/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func TestCheck_CheckMeta(t *testing.T) {
type fields struct {
checkBundle *bundle.Bundle
}
tests := []struct { //nolint:govet
name string
tests := []struct {
fields fields
want *Meta
name string
wantErr bool
}{
{"nil checkbundle", fields{}, nil, true},
{"checkbundle (nil bundle)", fields{checkBundle: &bundle.Bundle{}}, nil, true},
{name: "nil checkbundle", fields: fields{}, want: nil, wantErr: true},
{name: "checkbundle (nil bundle)", fields: fields{checkBundle: &bundle.Bundle{}}, want: nil, wantErr: true},
}
for _, tt := range tests {
tt := tt
Expand Down
2 changes: 0 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ type Config struct {
DebugAPI bool `mapstructure:"debug_api" json:"debug_api" yaml:"debug_api" toml:"debug_api"`
}

//
// NOTE: adding a Key* MUST be reflected in the Config structures above.
//
const (
// KeyAPICAFile custom ca for circonus api (e.g. inside).
KeyAPICAFile = "api.ca_file"
Expand Down
8 changes: 4 additions & 4 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package config

import (
"io/ioutil"
"io"
"testing"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestShowConfig(t *testing.T) {
t.Log("YAML")
{
viper.Set(KeyShowConfig, "yaml")
err := ShowConfig(ioutil.Discard)
err := ShowConfig(io.Discard)
if err != nil {
t.Fatalf("expected no error, got %s", err)
}
Expand All @@ -52,7 +52,7 @@ func TestShowConfig(t *testing.T) {
t.Log("TOML")
{
viper.Set(KeyShowConfig, "toml")
err := ShowConfig(ioutil.Discard)
err := ShowConfig(io.Discard)
if err != nil {
t.Fatalf("expected no error, got %s", err)
}
Expand All @@ -61,7 +61,7 @@ func TestShowConfig(t *testing.T) {
t.Log("JSON")
{
viper.Set(KeyShowConfig, "json")
err := ShowConfig(ioutil.Discard)
err := ShowConfig(io.Discard)
if err != nil {
t.Fatalf("expected no error, got %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/config/cosi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package config
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"

Expand Down Expand Up @@ -89,7 +89,7 @@ func loadCosiAPIConfig() (*APIConfig, error) {

// loadCosiV1Config loads (currently, only api) portion of cosi configuration.
func loadCosiV1Config(cfgFile string) (*APIConfig, error) {
data, err := ioutil.ReadFile(cfgFile)
data, err := os.ReadFile(cfgFile)
if err != nil {
return nil, fmt.Errorf("unable to access cosi config: %w", err)
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func loadCosiV2Config(cfgFile string) (*APIConfig, error) {

// loadChecKConfig loads (currently, only cid) portion of a cosi check config.
func loadCheckConfig(cfgFile string) (string, error) {
data, err := ioutil.ReadFile(cfgFile)
data, err := os.ReadFile(cfgFile)
if err != nil {
return "", fmt.Errorf("unable to access cosi check config: %w", err)
}
Expand Down
Loading

0 comments on commit 5a93262

Please sign in to comment.