Skip to content

Commit

Permalink
Merge pull request opensearch-project#303 from kakkoyun/reduce_noisy_…
Browse files Browse the repository at this point in the history
…logging

*: Reduce noisy logging
  • Loading branch information
kakkoyun authored Mar 22, 2022
2 parents 5d05bb8 + 53c952b commit c9a40aa
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/debuginfo/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (u *Uploader) UploadAll(ctx context.Context, dbgInfoFilePaths map[string]st
}

level.Debug(u.logger).Log(
"msg", "debug info uploaded successfully",
"msg", "debug information uploaded successfully",
"buildid", buildID, "file", filePath,
)
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/discovery/discovery_manager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 The Prometheus Authors
// Copyright (c) 2022 The Parca 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
Expand All @@ -10,6 +10,7 @@
// 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 discovery

Expand Down Expand Up @@ -185,7 +186,7 @@ func (m *Manager) StartCustomProvider(ctx context.Context, name string, worker D
}

func (m *Manager) startProvider(ctx context.Context, p *provider) {
level.Debug(m.logger).Log("msg", "Starting provider", "provider", p.name, "subs", fmt.Sprintf("%v", p.subs))
level.Debug(m.logger).Log("msg", "starting provider", "provider", p.name, "subs", fmt.Sprintf("%v", p.subs))
ctx, cancel := context.WithCancel(ctx)
updates := make(chan []*target.Group)

Expand All @@ -207,7 +208,7 @@ func (m *Manager) updater(ctx context.Context, p *provider, updates chan []*targ
case tgs, ok := <-updates:
m.metrics.receivedUpdates.Inc()
if !ok {
level.Debug(m.logger).Log("msg", "Discoverer channel closed", "provider", p.name)
level.Debug(m.logger).Log("msg", "discoverer channel closed", "provider", p.name)
return
}

Expand Down Expand Up @@ -239,7 +240,7 @@ func (m *Manager) sender() {
case m.syncCh <- m.allGroups():
default:
m.metrics.delayedUpdates.Inc()
level.Debug(m.logger).Log("msg", "Discovery receiver's channel was full so will retry the next cycle")
level.Debug(m.logger).Log("msg", "discovery receiver's channel was full so will retry the next cycle")
select {
case m.triggerSend <- struct{}{}:
default:
Expand Down
7 changes: 6 additions & 1 deletion pkg/maps/mapping.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Parca Authors
// Copyright (c) 2022 The Parca 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
Expand All @@ -10,13 +10,18 @@
// 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 maps

import (
"errors"

"github.com/google/pprof/profile"
)

var ErrNotFound = errors.New("not found")

type Mapping struct {
fileCache *PIDMappingFileCache
pidMappings map[uint32][]*profile.Mapping
Expand Down
6 changes: 5 additions & 1 deletion pkg/maps/maps.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Parca Authors
// Copyright (c) 2022 The Parca 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
Expand All @@ -10,6 +10,7 @@
// 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 maps

Expand Down Expand Up @@ -71,6 +72,9 @@ func (c *PIDMappingFileCache) mappingForPID(pid uint32) ([]*profile.Mapping, err
mapsFile := fmt.Sprintf("/proc/%d/maps", pid)
h, err := hash.File(c.fs, mapsFile)
if err != nil {
if os.IsNotExist(err) {
return nil, ErrNotFound
}
return nil, err
}
if c.pidMapHash[pid] == h {
Expand Down
7 changes: 4 additions & 3 deletions pkg/objectfile/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strconv"
"strings"

"github.com/go-kit/log"
burrow "github.com/goburrow/cache"
"github.com/google/pprof/profile"
)
Expand All @@ -35,8 +34,10 @@ type cache struct {
}

// NewCache creates a new cache for object files.
func NewCache(logger log.Logger, size int) Cache {
return &cache{cache: burrow.New(burrow.WithMaximumSize(size))}
func NewCache(size int) Cache {
return &cache{
cache: burrow.New(burrow.WithMaximumSize(size)),
}
}

// ObjectFileForProcess returns the object file for the given mapping and process id.
Expand Down
3 changes: 2 additions & 1 deletion pkg/objectfile/object_file.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The Parca Authors
// Copyright (c) 2022 The Parca 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
Expand All @@ -10,6 +10,7 @@
// 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.
//

// This package includes modified code from the github.com/google/pprof/internal/binutils

Expand Down
16 changes: 12 additions & 4 deletions pkg/perf/perf.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2021 The Parca Authors
//
// Copyright (c) 2022 The Parca 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
Expand All @@ -11,6 +10,7 @@
// 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 perf

Expand Down Expand Up @@ -49,7 +49,10 @@ type Map struct {

type realfs struct{}

var ErrNoSymbolFound = errors.New("no symbol found")
var (
ErrNotFound = errors.New("not found")
ErrNoSymbolFound = errors.New("no symbol found")
)

func (f *realfs) Open(name string) (fs.File, error) {
return os.Open(name)
Expand Down Expand Up @@ -125,6 +128,9 @@ func (p *Cache) CacheForPID(pid uint32) (*Map, error) {
if !found {
nsPids, err := findNSPIDs(p.fs, pid)
if err != nil {
if os.IsNotExist(err) {
return nil, ErrNotFound
}
return nil, err
}

Expand All @@ -133,9 +139,11 @@ func (p *Cache) CacheForPID(pid uint32) (*Map, error) {
}

perfFile := fmt.Sprintf("/proc/%d/root/tmp/perf-%d.map", pid, nsPid)
// TODO(zecke): Log other than file not found errors?
h, err := hash.File(p.fs, perfFile)
if err != nil {
if os.IsNotExist(err) {
return nil, ErrNotFound
}
return nil, err
}

Expand Down
14 changes: 10 additions & 4 deletions pkg/profiler/profiler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Parca Authors
// Copyright (c) 2022 The Parca 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
Expand All @@ -10,6 +10,7 @@
// 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 profiler

Expand All @@ -18,6 +19,7 @@ import (
"context"
_ "embed"
"encoding/binary"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -298,7 +300,7 @@ func (p *CgroupProfiler) Run(ctx context.Context) error {
captureTime := time.Now()
err := p.profileLoop(ctx, captureTime)
if err != nil {
level.Debug(p.logger).Log("msg", "profile loop error", "err", err)
level.Warn(p.logger).Log("msg", "profile loop error", "err", err)
}

p.loopReport(captureTime, err)
Expand Down Expand Up @@ -434,7 +436,9 @@ func (p *CgroupProfiler) profileLoop(ctx context.Context, captureTime time.Time)
if err != nil {
// We expect only a minority of processes to have a JIT and produce
// the perf map.
level.Debug(p.logger).Log("msg", "no perfmap", "err", err)
if !errors.Is(err, perf.ErrNotFound) {
level.Warn(p.logger).Log("msg", "failed to obtain perf map for pid", "pid", pid, "err", err)
}
}
// Collect User stack trace samples.
for _, addr := range stack[:stackDepth] {
Expand All @@ -446,7 +450,9 @@ func (p *CgroupProfiler) profileLoop(ctx context.Context, captureTime time.Time)

m, err := mapping.PIDAddrMapping(pid, addr)
if err != nil {
level.Debug(p.logger).Log("msg", "failed to get process mapping", "err", err)
if !errors.Is(err, maps.ErrNotFound) {
level.Warn(p.logger).Log("msg", "failed to get process mapping", "err", err)
}
}

var objFile *objectfile.MappedObjectFile
Expand Down
5 changes: 3 additions & 2 deletions pkg/target/manager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 The Parca Authors
// Copyright (c) 2022 The Parca 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
Expand All @@ -10,6 +10,7 @@
// 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 target

Expand Down Expand Up @@ -91,7 +92,7 @@ func (m *Manager) reconcileTargets(ctx context.Context, targetSets map[string][]
cacheSize := len(targetSet) * 5
pp = NewProfilerPool(
ctx, m.logger, m.reg,
m.ksymCache, objectfile.NewCache(m.logger, cacheSize),
m.ksymCache, objectfile.NewCache(cacheSize),
m.writeClient, m.debugInfoClient,
m.profilingDuration, m.externalLabels,
m.tmp,
Expand Down
5 changes: 3 additions & 2 deletions pkg/target/profiler_pool.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 The Parca Authors
// Copyright (c) 2022 The Parca 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
Expand All @@ -10,6 +10,7 @@
// 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 target

Expand Down Expand Up @@ -145,7 +146,7 @@ func (pp *ProfilerPool) Sync(tg []*Group) {

go func() {
err := newProfiler.Run(pp.ctx)
level.Debug(pp.logger).Log("msg", "profiler ended with error", "error", err, "labels", newProfiler.Labels().String())
level.Warn(pp.logger).Log("msg", "profiler ended with error", "error", err, "labels", newProfiler.Labels().String())
}()

pp.activeTargets[h] = newTarget
Expand Down

0 comments on commit c9a40aa

Please sign in to comment.