Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate STEAMPIPE_DIAGNOSTICS_LEVEL. Closes #665 #664

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions plugin/env.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package plugin

import (
"fmt"
"golang.org/x/exp/maps"
"log"
"math"
"os"
"strconv"
"strings"
)

const (
envMaxConcurrentConnection = "STEAMPIPE_MAX_CONCURRENT_CONNECTIONS"
envMaxMemoryMb = "STEAMPIPE_MAX_MEMORY_MB"
envFreeMemInterval = "STEAMPIPE_FREE_MEM_INTERVAL"
defaultMaxConcurrentConnections = 25 // default to 25 concurrent connections
defaultMaxMemoryMb = math.MaxInt64 // default to no memory limit
defaultFreeMemInterval = 100 // default to freeing memory every 100 rows
defaultMaxConcurrentConnections = 25 // default to 25 concurrent connections
defaultFreeMemInterval = 100 // default to freeing memory every 100 rows

EnvDiagnosticsLevel = "STEAMPIPE_DIAGNOSTIC_LEVEL"
EnvLegacyDiagnosticsLevel = "STEAMPIPE_DIAGNOSTICS_LEVEL"
DiagnosticsAll = "ALL"
DiagnosticsNone = "NONE"
)

var ValidDiagnosticsLevels = map[string]struct{}{
DiagnosticsAll: {},
DiagnosticsNone: {},
}

func getMaxConcurrentConnections() int {
maxConcurrentConnections, _ := strconv.Atoi(os.Getenv(envMaxConcurrentConnection))
if maxConcurrentConnections == 0 {
Expand All @@ -25,17 +35,6 @@ func getMaxConcurrentConnections() int {
return maxConcurrentConnections
}

func GetMaxMemoryBytes() int64 {
maxMemoryMb, _ := strconv.Atoi(os.Getenv(envMaxMemoryMb))
if maxMemoryMb == 0 {
log.Printf("[TRACE] No memory limit set")
maxMemoryMb = defaultMaxMemoryMb
} else {
log.Printf("[TRACE] Setting max memory %dMb", maxMemoryMb)
}
return int64(1024 * 1024 * maxMemoryMb)
}

func GetFreeMemInterval() int64 {
freeMemInterval := defaultFreeMemInterval
intervalEnv, ok := os.LookupEnv(envFreeMemInterval)
Expand All @@ -48,3 +47,23 @@ func GetFreeMemInterval() int64 {

return int64(freeMemInterval)
}

func loadDiagnosticsEnvVar() string {
// load both the legacy and current diagnostics env vars
diagnostics := strings.ToUpper(os.Getenv(EnvLegacyDiagnosticsLevel))
if newDiagnostics, isSet := os.LookupEnv(EnvDiagnosticsLevel); isSet {
diagnostics = strings.ToUpper(newDiagnostics)
}
return diagnostics
}

func ValidateDiagnosticsEnvVar() error {
diagnostics := loadDiagnosticsEnvVar()
if diagnostics == "" {
return nil
}
if _, isValid := ValidDiagnosticsLevels[strings.ToUpper(diagnostics)]; !isValid {
return fmt.Errorf(`invalid value of '%s' (%s), must be one of: %s`, EnvDiagnosticsLevel, diagnostics, strings.Join(maps.Keys(ValidDiagnosticsLevels), ", "))
}
return nil
}
18 changes: 1 addition & 17 deletions plugin/row_with_metadata.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
package plugin

import (
"os"
"strings"
)

const (
EnvDiagnosticsLevel = "STEAMPIPE_DIAGNOSTICS_LEVEL"
DiagnosticsAll = "ALL"
DiagnosticsNone = "NONE"
)

var ValidDiagnosticsLevels = map[string]struct{}{
DiagnosticsAll: {},
DiagnosticsNone: {},
}

type hydrateMetadata struct {
Type string `json:"type"`
FuncName string `json:"function_name"`
Expand All @@ -38,7 +22,7 @@ func newRowCtxData(rd *rowData) *rowCtxData {
Connection: d.Connection.Name,
}

if strings.ToUpper(os.Getenv(EnvDiagnosticsLevel)) == DiagnosticsAll {
if loadDiagnosticsEnvVar() == DiagnosticsAll {
calls := append([]*hydrateMetadata{d.fetchMetadata}, rd.hydrateMetadata...)
if d.parentHydrateMetadata != nil {
calls = append([]*hydrateMetadata{d.parentHydrateMetadata}, calls...)
Expand Down
Loading