mirror of
https://github.com/status-im/consul.git
synced 2025-01-20 18:50:04 +00:00
d24156db14
* debug: remove the CLI check for debug_enabled The API allows collecting profiles even debug_enabled=false as long as ACLs are enabled. Remove this check from the CLI so that users do not need to set debug_enabled=true for no reason. Also: - fix the API client to return errors on non-200 status codes for debug endpoints - improve the failure messages when pprof data can not be collected Co-Authored-By: Dhia Ayachi <dhia@hashicorp.com> * remove parallel test runs parallel runs create a race condition that fail the debug tests * snapshot the timestamp at the beginning of the capture - timestamp used to create the capture sub folder is snapshot only at the beginning of the capture and reused for subsequent captures - capture append to the file if it already exist * Revert "snapshot the timestamp at the beginning of the capture" This reverts commit c2d03346 * Refactor captureDynamic to extract capture logic for each item in a different func * snapshot the timestamp at the beginning of the capture - timestamp used to create the capture sub folder is snapshot only at the beginning of the capture and reused for subsequent captures - capture append to the file if it already exist * Revert "snapshot the timestamp at the beginning of the capture" This reverts commit c2d03346 * Refactor captureDynamic to extract capture logic for each item in a different func * extract wait group outside the go routine to avoid a race condition * capture pprof in a separate go routine * perform a single capture for pprof data for the whole duration * add missing vendor dependency * add a change log and fix documentation to reflect the change * create function for timestamp dir creation and simplify error handling * use error groups and ticker to simplify interval capture loop * Logs, profile and traces are captured for the full duration. Metrics, Heap and Go routines are captured every interval * refactor Logs capture routine and add log capture specific test * improve error reporting when log test fail * change test duration to 1s * make time parsing in log line more robust * refactor log time format in a const * test on log line empty the earliest possible and return Co-authored-by: Freddy <freddygv@users.noreply.github.com> * rename function to captureShortLived * more specific changelog Co-authored-by: Paul Banks <banks@banksco.de> * update documentation to reflect current implementation * add test for behavior when invalid param is passed to the command * fix argument line in test * a more detailed description of the new behaviour Co-authored-by: Paul Banks <banks@banksco.de> * print success right after the capture is done * remove an unnecessary error check Co-authored-by: Daniel Nephin <dnephin@hashicorp.com> * upgraded github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57 => v0.0.0-20210601050228-01bbb1931b22 Co-authored-by: Daniel Nephin <dnephin@hashicorp.com> Co-authored-by: Freddy <freddygv@users.noreply.github.com> Co-authored-by: Paul Banks <banks@banksco.de>
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
// Copyright 2016 Google Inc. All Rights Reserved.
|
|
//
|
|
// 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 profile
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// SampleIndexByName returns the appropriate index for a value of sample index.
|
|
// If numeric, it returns the number, otherwise it looks up the text in the
|
|
// profile sample types.
|
|
func (p *Profile) SampleIndexByName(sampleIndex string) (int, error) {
|
|
if sampleIndex == "" {
|
|
if dst := p.DefaultSampleType; dst != "" {
|
|
for i, t := range sampleTypes(p) {
|
|
if t == dst {
|
|
return i, nil
|
|
}
|
|
}
|
|
}
|
|
// By default select the last sample value
|
|
return len(p.SampleType) - 1, nil
|
|
}
|
|
if i, err := strconv.Atoi(sampleIndex); err == nil {
|
|
if i < 0 || i >= len(p.SampleType) {
|
|
return 0, fmt.Errorf("sample_index %s is outside the range [0..%d]", sampleIndex, len(p.SampleType)-1)
|
|
}
|
|
return i, nil
|
|
}
|
|
|
|
// Remove the inuse_ prefix to support legacy pprof options
|
|
// "inuse_space" and "inuse_objects" for profiles containing types
|
|
// "space" and "objects".
|
|
noInuse := strings.TrimPrefix(sampleIndex, "inuse_")
|
|
for i, t := range p.SampleType {
|
|
if t.Type == sampleIndex || t.Type == noInuse {
|
|
return i, nil
|
|
}
|
|
}
|
|
|
|
return 0, fmt.Errorf("sample_index %q must be one of: %v", sampleIndex, sampleTypes(p))
|
|
}
|
|
|
|
func sampleTypes(p *Profile) []string {
|
|
types := make([]string, len(p.SampleType))
|
|
for i, t := range p.SampleType {
|
|
types[i] = t.Type
|
|
}
|
|
return types
|
|
}
|