Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2f7c60f
refactor: added stat_statements component configuration
SimonSerrano Aug 19, 2025
256801b
test: added stat_statements to unmarshal test
SimonSerrano Aug 19, 2025
3a3815b
refactor: override kingpin flags to pass stat_statements flags
SimonSerrano Aug 19, 2025
fdf176d
docs(changelog): updated changelog (#4004)
SimonSerrano Sep 7, 2025
2006396
refactor: added stat_statements component configuration
SimonSerrano Aug 19, 2025
0df8ded
test: added stat_statements to unmarshal test
SimonSerrano Aug 19, 2025
c02d73d
refactor: override kingpin flags to pass stat_statements flags
SimonSerrano Aug 19, 2025
990a93c
docs(changelog): updated changelog (#4004)
SimonSerrano Sep 7, 2025
458a2e7
Merge branch 'ss/postgres_exporter-flags' of https://github.com/Simon…
SimonSerrano Sep 7, 2025
3c8b6ac
docs(changelog): refined changelog entry (#4004)
SimonSerrano Sep 7, 2025
b64e082
docs(reference): added stat_statements documentation
SimonSerrano Sep 7, 2025
583fa26
docs(prostgres exporter): query length default is 120
SimonSerrano Sep 14, 2025
966d64f
refactor(postgres exporter): namespaced stat statements config for in…
SimonSerrano Sep 14, 2025
b527881
refactor(postgres exporter): renamed variable for clarity #4004
SimonSerrano Sep 14, 2025
4eb1bb8
test(postgres exporter): indent using spaces #4004
SimonSerrano Sep 14, 2025
42118d0
docs(postgres exporter): format documentation #4004
SimonSerrano Sep 14, 2025
9764c68
docs(postgres exporter): format documentation #4004
SimonSerrano Sep 14, 2025
2f6a948
docs(postgres exporter): format array
SimonSerrano Sep 14, 2025
1fff827
Merge branch 'ss/postgres_exporter-flags' of https://github.com/Simon…
SimonSerrano Sep 14, 2025
a2a6056
refactor: added stat_statements component configuration
SimonSerrano Aug 19, 2025
c361ae0
test: added stat_statements to unmarshal test
SimonSerrano Aug 19, 2025
f125883
refactor: override kingpin flags to pass stat_statements flags
SimonSerrano Aug 19, 2025
d0b2217
docs(changelog): updated changelog (#4004)
SimonSerrano Sep 7, 2025
2f5e9d7
docs(changelog): refined changelog entry (#4004)
SimonSerrano Sep 7, 2025
ce00a14
docs(reference): added stat_statements documentation
SimonSerrano Sep 7, 2025
6bc86a2
docs(prostgres exporter): query length default is 120
SimonSerrano Sep 14, 2025
faebab6
refactor(postgres exporter): namespaced stat statements config for in…
SimonSerrano Sep 14, 2025
31792ea
refactor(postgres exporter): renamed variable for clarity #4004
SimonSerrano Sep 14, 2025
bf82fce
test(postgres exporter): indent using spaces #4004
SimonSerrano Sep 14, 2025
bf76746
docs(postgres exporter): format array
SimonSerrano Sep 14, 2025
c651731
docs(postgres exporter): format documentation #4004
SimonSerrano Sep 14, 2025
3ff7d6e
Merge branch 'ss/postgres_exporter-flags' of https://github.com/Simon…
SimonSerrano Sep 14, 2025
107a00d
test(postgres exporter): indent using tabs
SimonSerrano Sep 16, 2025
680f11f
refactor(postgres exporter): check for errors when setting kingpin fl…
SimonSerrano Sep 16, 2025
5d40656
docs(postgres exporter): typo in code documentation #4004
SimonSerrano Sep 16, 2025
2b733b4
test(postgres exporter): added QueryLength default to expected postgr…
SimonSerrano Sep 16, 2025
2bc5c1a
test(postgres exporter): converter includes empty stat_statements by …
SimonSerrano Sep 16, 2025
3e62e3b
Revert "test(postgres exporter): converter includes empty stat_statem…
SimonSerrano Sep 19, 2025
672fadc
refactor(postgres exporter): flattened namespaced config to match oth…
SimonSerrano Sep 19, 2025
795f7df
Revert "refactor(postgres exporter): flattened namespaced config to m…
cristiangreco Sep 30, 2025
ef1cd4b
make field nullable
cristiangreco Sep 30, 2025
49ab6db
Merge pull request #1 from cristiangreco/ss/postgres_exporter-flags
SimonSerrano Oct 8, 2025
336e042
docs(postgres exporter): removed duplicate line #4004
SimonSerrano Oct 8, 2025
d9281c9
Merge remote-tracking branch 'upstream/main' into ss/postgres_exporte…
SimonSerrano Oct 8, 2025
60a392b
docs(changelog): moved to unreleased section
SimonSerrano Oct 9, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Main (unreleased)

- Add `encoding.url_encode` and `encoding.url_decode` std lib functions. (@kalleep)

- Add a `stat_statements` configuration block to the `prometheus.exporter.postgres` component to enable selecting both the query ID and the full SQL statement. The new block includes one option to enable statement selection, and another to configure the maximum length of the statement text. (@SimonSerrano)

### Enhancements

- Fix `pyroscope.write` component's `AppendIngest` method to respect configured timeout and implement retry logic. The method now properly uses the configured `remote_timeout`, includes retry logic with exponential backoff, and tracks metrics for sent/dropped bytes and profiles consistently with the `Append` method. (@korniltsev)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ If `enabled` is set to `true` and no allowlist or denylist is specified, the exp

If `autodiscovery` is disabled, neither `database_allowlist` nor `database_denylist` has any effect.

### `stat_statements`

The `stat_statements` block configures the selection of both the query ID and the full SQL statement. This configuration takes effect only when the `stat_statements` collector is enabled.

The following aeguments are supported:
| Name | Type | Description | Default | Required |
|----------------------|----------------|--------------------------------------------------------------------------------|---------|----------|
| `include_query` | `bool` | Enable the selection of query ID and SQL statement. | `false` | no |
| `query_length` | `number` | Maximum length of the statement query text. | `200` | no |

## Exported fields

{{< docs/shared lookup="reference/components/exporter-component-exports.md" source="alloy" version="<ALLOY_VERSION>" >}}
Expand Down
15 changes: 14 additions & 1 deletion internal/component/prometheus/exporter/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ var DefaultArguments = Arguments{
},
DisableDefaultMetrics: false,
CustomQueriesConfigPath: "",
StatStatementFlags: StatStatementFlags{
IncludeQuery: false,
QueryLength: 120,
},
}

// Arguments configures the prometheus.exporter.postgres component
Expand All @@ -53,7 +57,8 @@ type Arguments struct {
EnabledCollectors []string `alloy:"enabled_collectors,attr,optional"`

// Blocks
AutoDiscovery AutoDiscovery `alloy:"autodiscovery,block,optional"`
AutoDiscovery AutoDiscovery `alloy:"autodiscovery,block,optional"`
StatStatementFlags StatStatementFlags `alloy:"stat_statements,block,optional"`
}

func (a *Arguments) Validate() error {
Expand All @@ -73,6 +78,12 @@ type AutoDiscovery struct {
DatabaseDenylist []string `alloy:"database_denylist,attr,optional"`
}

// StatStatementFlags describe the flags to pass along the activation of the stat_statements collector
type StatStatementFlags struct {
IncludeQuery bool `alloy:"include_query,attr,optional"`
QueryLength uint `alloy:"query_length,attr,optional"`
}

// SetToDefault implements syntax.Defaulter.
func (a *Arguments) SetToDefault() {
*a = DefaultArguments
Expand All @@ -89,6 +100,8 @@ func (a *Arguments) convert(instanceName string) *postgres_exporter.Config {
QueryPath: a.CustomQueriesConfigPath,
Instance: instanceName,
EnabledCollectors: a.EnabledCollectors,
IncludeQuery: a.StatStatementFlags.IncludeQuery,
QueryLength: a.StatStatementFlags.QueryLength,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func TestAlloyConfigUnmarshal(t *testing.T) {
disable_settings_metrics = true
disable_default_metrics = true
custom_queries_config_path = "/tmp/queries.yaml"

stat_statements {
include_query = true
query_length = 200
}

autodiscovery {
enabled = false
Expand All @@ -37,6 +42,10 @@ func TestAlloyConfigUnmarshal(t *testing.T) {
},
DisableDefaultMetrics: true,
CustomQueriesConfigPath: "/tmp/queries.yaml",
StatStatementFlags: StatStatementFlags{
IncludeQuery: true,
QueryLength: 200,
},
}

require.Equal(t, expected, args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"

"github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/grafana/alloy/internal/runtime/logging"
"github.com/grafana/alloy/internal/static/integrations"
Expand Down Expand Up @@ -39,6 +40,9 @@ type Config struct {
// this is only used for the first DSN provided and only some collectors can be enabled/disabled this way. See the
// user-facing docs for more information.
EnabledCollectors []string

IncludeQuery bool
QueryLength uint
}

// Name returns the name of the integration this config is for.
Expand Down Expand Up @@ -173,6 +177,20 @@ func New(log log.Logger, cfg *Config) (integrations.Integration, error) {
return integrations.NewCollectorIntegration(cfg.Name(), integrations.WithCollectors(e)), nil
}

// This is a hack to force the command line flag values for the stat_statements collector.
// These flags are not exposed outside the package and cannot be mutated afterwards.
if cfg.IncludeQuery {
iqf := kingpin.CommandLine.GetFlag("collector.stat_statements.include_query")
qlf := kingpin.CommandLine.GetFlag("collector.stat_statements.query_length")

if iqf == nil || qlf == nil {
return nil, fmt.Errorf("failed to find collector.stat_statements.include_query or collector.stat_statements.query_length in postgres_exporter")
}

iqf.Model().Value.Set("true")
qlf.Model().Value.Set(fmt.Sprintf("%d", cfg.QueryLength))
}

// On top of the exporter's metrics, the postgres exporter also has metrics exposed via collector package.
// However, these can only work for the first DSN provided. This matches the current implementation of the exporter.
// TODO: Once https://github.com/prometheus-community/postgres_exporter/issues/999 is addressed, update the exporter
Expand Down