Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: prometheus/common
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.60.0
Choose a base ref
...
head repository: prometheus/common
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.60.1
Choose a head ref
  • 4 commits
  • 4 files changed
  • 4 contributors

Commits on Oct 11, 2024

  1. promslog: Only log basename, not full path

    Signed-off-by: Julien <roidelapluie@o11y.eu>
    Julien committed Oct 11, 2024
    Copy the full SHA
    fdc50c7 View commit details
  2. Merge pull request #705 from roidelapluie/sourcefile

    promslog: Only log basename, not full path
    roidelapluie authored Oct 11, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    a9d2e3f View commit details

Commits on Oct 14, 2024

  1. Reload certificates even when no CA is used (#707)

    This commit uses the roundtripper that reloads itself even when there is
    no CA, so when keys and certs are reloaded on disk, we have a new
    rountripper and we use the new certificates.
    
    Signed-off-by: Julien <roidelapluie@o11y.eu>
    roidelapluie authored Oct 14, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    0d2e2e5 View commit details
  2. Update common Prometheus files (#701)

    Signed-off-by: prombot <prometheus-team@googlegroups.com>
    Co-authored-by: Ben Kochie <superq@gmail.com>
    prombot and SuperQ authored Oct 14, 2024

    Verified

    This commit was created on github.com and signed with GitHub’s verified signature.
    Copy the full SHA
    653e0fa View commit details
Showing with 66 additions and 6 deletions.
  1. +1 −1 .github/workflows/golangci-lint.yml
  2. +7 −3 config/http_config.go
  3. +14 −2 promslog/slog.go
  4. +44 −0 promslog/slog_test.go
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Install Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
10 changes: 7 additions & 3 deletions config/http_config.go
Original file line number Diff line number Diff line change
@@ -679,8 +679,8 @@ func NewRoundTripperFromConfigWithContext(ctx context.Context, cfg HTTPClientCon
if err != nil {
return nil, err
}
if tlsSettings.CA == nil || tlsSettings.CA.Immutable() {
// No need for a RoundTripper that reloads the CA file automatically.
if tlsSettings.immutable() {
// No need for a RoundTripper that reloads the files automatically.
return newRT(tlsConfig)
}
return NewTLSRoundTripperWithContext(ctx, tlsConfig, tlsSettings, newRT)
@@ -914,7 +914,7 @@ func (rt *oauth2RoundTripper) newOauth2TokenSource(req *http.Request, secret str
if err != nil {
return nil, nil, err
}
if tlsSettings.CA == nil || tlsSettings.CA.Immutable() {
if tlsSettings.immutable() {
t, _ = tlsTransport(tlsConfig)
} else {
t, err = NewTLSRoundTripperWithContext(req.Context(), tlsConfig, tlsSettings, tlsTransport)
@@ -1259,6 +1259,10 @@ type TLSRoundTripperSettings struct {
Key SecretReader
}

func (t *TLSRoundTripperSettings) immutable() bool {
return (t.CA == nil || t.CA.Immutable()) && (t.Cert == nil || t.Cert.Immutable()) && (t.Key == nil || t.Key.Immutable())
}

func NewTLSRoundTripper(
cfg *tls.Config,
settings TLSRoundTripperSettings,
16 changes: 14 additions & 2 deletions promslog/slog.go
Original file line number Diff line number Diff line change
@@ -66,6 +66,17 @@ var (
default:
}

return a
}
truncateSourceAttrFunc = func(groups []string, a slog.Attr) slog.Attr {
if a.Key != slog.SourceKey {
return a
}

if src, ok := a.Value.Any().(*slog.Source); ok {
a.Value = slog.StringValue(filepath.Base(src.File) + ":" + strconv.Itoa(src.Line))
}

return a
}
)
@@ -165,8 +176,9 @@ func New(config *Config) *slog.Logger {
}

logHandlerOpts := &slog.HandlerOptions{
Level: config.Level.lvl,
AddSource: true,
Level: config.Level.lvl,
AddSource: true,
ReplaceAttr: truncateSourceAttrFunc,
}

if config.Style == GoKitStyle {
44 changes: 44 additions & 0 deletions promslog/slog_test.go
Original file line number Diff line number Diff line change
@@ -146,3 +146,47 @@ func TestDynamicLevels(t *testing.T) {
})
}
}

func TestTruncateSourceFileName_DefaultStyle(t *testing.T) {
var buf bytes.Buffer

config := &Config{
Writer: &buf,
}

logger := New(config)
logger.Info("test message")

output := buf.String()

if !strings.Contains(output, "source=slog_test.go:") {
t.Errorf("Expected source file name to be truncated to basename, got: %s", output)
}

if strings.Contains(output, "/") {
t.Errorf("Expected no directory separators in source file name, got: %s", output)
}
}

func TestTruncateSourceFileName_GoKitStyle(t *testing.T) {
var buf bytes.Buffer

config := &Config{
Writer: &buf,
Style: GoKitStyle,
}

logger := New(config)
logger.Info("test message")

output := buf.String()

// In GoKitStyle, the source key is "caller".
if !strings.Contains(output, "caller=slog_test.go:") {
t.Errorf("Expected caller to contain basename of source file, got: %s", output)
}

if strings.Contains(output, "/") {
t.Errorf("Expected no directory separators in caller, got: %s", output)
}
}