Skip to content

Commit

Permalink
Cherry pick for rc1 (#2059)
Browse files Browse the repository at this point in the history
* update changelog version

* Prototype targets.merge function (array.combine_maps) (#1826)

* Prototype map.inner_join function

* Rename to "targets.merge", remove unnecessary params

* Add failure tests

* Delete incorrect comment

* rename targets.merge to array.combine_maps, mark it as experimental, make is more permissive and add tests

* update changelog

* Update CHANGELOG.md

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* Update docs/sources/reference/stdlib/array.md

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* Update docs/sources/reference/stdlib/array.md

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* Update docs/sources/reference/stdlib/array.md

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* rename mapCombine to combineMaps

* document panic

* add equal test

* add more tests

* Update syntax/internal/stdlib/stdlib.go

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* Update syntax/internal/stdlib/stdlib.go

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* add examples in doc

* fix error propagation

* remove value nul on len function

* refactor code into a traversal function

* update doc to avoid modifying the experimental shared doc

---------

Co-authored-by: William Dumont <william.dumont@grafana.com>
Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* Implement an initial version of the support bundle in Alloy (#2009)

* Implement an initial version of the support bundle in Alloy

* Add documentation for support bundle

* Update changelog

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Initial PR feedback

* Rewrite http service to use logging library internal to alloy

* Revert accidental commit of e2e test changes

* Fix comment on exported function

* Clean up added host variable that is no longer used

* Refactor usage of logger in http service

* Update internal/service/http/http.go

Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

* implement PR feedback

* Hide support bundle behind public preview stability level

* Update docs based on feedback

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* Update docs/sources/troubleshoot/support_bundle.md

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>

* More PR feedback in docs

* Fix race condition in logger

* Add a note about backward-compatibility exception

---------

Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
Co-authored-by: Piotr <17101802+thampiotr@users.noreply.github.com>

---------

Co-authored-by: Paulin Todev <paulin.todev@gmail.com>
Co-authored-by: William Dumont <william.dumont@grafana.com>
Co-authored-by: Sam DeHaan <dehaansa@gmail.com>
Co-authored-by: Clayton Cornell <131809008+clayton-cornell@users.noreply.github.com>
  • Loading branch information
5 people authored Nov 11, 2024
1 parent 769e7c3 commit 377fe47
Show file tree
Hide file tree
Showing 19 changed files with 829 additions and 33 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This document contains a historical list of changes between releases. Only
changes that impact end-user behavior are listed; changes to documentation or
internal API changes are not present.

v1.5.0-rc.0
v1.5.0-rc.1
-----------------

### Breaking changes
Expand All @@ -25,7 +25,10 @@ v1.5.0-rc.0

### Features

- Add support bundle generation via the API endpoint /-/support (@dehaansa)

- Add the function `path_join` to the stdlib. (@wildum)

- Add `pyroscope.receive_http` component to receive and forward Pyroscope profiles (@marcsanmi)

- Add support to `loki.source.syslog` for the RFC3164 format ("BSD syslog"). (@sushain97)
Expand All @@ -37,6 +40,8 @@ v1.5.0-rc.0
- (_Experimental_) Add a `prometheus.write.queue` component to add an alternative to `prometheus.remote_write`
which allowing the writing of metrics to a prometheus endpoint. (@mattdurham)

- (_Experimental_) Add the `arrary.combine_maps` function to the stdlib. (@ptodev, @wildum)

### Enhancements

- The `mimir.rules.kubernetes` component now supports adding extra label matchers
Expand Down
2 changes: 2 additions & 0 deletions docs/sources/reference/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The following flags are supported:
* `--server.http.ui-path-prefix`: Base path where the UI is exposed (default `/`).
* `--storage.path`: Base directory where components can store data (default `data-alloy/`).
* `--disable-reporting`: Disable [data collection][] (default `false`).
* `--disable-support-bundle`: Disable [support bundle][] endpoint (default `false`).
* `--cluster.enabled`: Start {{< param "PRODUCT_NAME" >}} in clustered mode (default `false`).
* `--cluster.node-name`: The name to use for this node (defaults to the environment's hostname).
* `--cluster.join-addresses`: Comma-separated list of addresses to join the cluster at (default `""`). Mutually exclusive with `--cluster.discover-peers`.
Expand Down Expand Up @@ -178,6 +179,7 @@ Refer to [alloy convert][] for more details on how `extra-args` work.
[go-discover]: https://github.com/hashicorp/go-discover
[in-memory HTTP traffic]: ../../../get-started/component_controller/#in-memory-traffic
[data collection]: ../../../data-collection/
[support bundle]: ../../../troubleshoot/support_bundle
[components]: ../../get-started/components/
[component controller]: ../../../get-started/component_controller/
[UI]: ../../../troubleshoot/debug/#clustering-page
51 changes: 51 additions & 0 deletions docs/sources/reference/stdlib/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,54 @@ Elements within the list can be any type.
> array.concat([[1, 2], [3, 4]], [[5, 6]])
[[1, 2], [3, 4], [5, 6]]
```

## array.combine_maps

> **EXPERIMENTAL**: This is an [experimental][] feature. Experimental
> features are subject to frequent breaking changes, and may be removed with
> no equivalent replacement. The `stability.level` flag must be set to `experimental`
> to use the feature.
The `array.combine_maps` function allows you to join two arrays of maps if certain keys have matching values in both maps. It's particularly useful when combining labels of targets coming from different `prometheus.discovery.*` or `prometheus.exporter.*` components.
It takes three arguments:

* The first two arguments are a of type `list(map(string))`. The keys of the map are strings.
The value for each key could be of any Alloy type such as a `string`, `integer`, `map`, or a `capsule`.
* The third input is an `array` containing strings. The strings are the keys whose value has to match for maps to be combined.

The maps that don't contain all the keys provided in the third argument will be discarded. When maps are combined and both contain the same keys, the last value from the second argument will be used.

Pseudo function code:
```
for every map in arg1:
for every map in arg2:
if the condition key matches in both:
merge maps and add to result
```

### Examples

```alloy
> array.combine_maps([{"instance"="1.1.1.1", "team"="A"}], [{"instance"="1.1.1.1", "cluster"="prod"}], ["instance"])
[{"instance"="1.1.1.1", "team"="A", "cluster"="prod"}]
// Second map overrides the team in the first map
> array.combine_maps([{"instance"="1.1.1.1", "team"="A"}], [{"instance"="1.1.1.1", "team"="B"}], ["instance"])
[{"instance"="1.1.1.1", "team"="B"}]
// If multiple maps from the first argument match with multiple maps from the second argument, different combinations will be created.
> array.combine_maps([{"instance"="1.1.1.1", "team"="A"}, {"instance"="1.1.1.1", "team"="B"}], [{"instance"="1.1.1.1", "cluster"="prod"}, {"instance"="1.1.1.1", "cluster"="ops"}], ["instance"])
[{"instance"="1.1.1.1", "team"="A", "cluster"="prod"}, {"instance"="1.1.1.1", "team"="A", "cluster"="ops"}, {"instance"="1.1.1.1", "team"="B", "cluster"="prod"}, {"instance"="1.1.1.1", "team"="B", "cluster"="ops"}]
```

Examples using discovery and exporter components:
```alloy
> array.combine_maps(discovery.kubernetes.k8s_pods.targets, prometheus.exporter.postgres, ["instance"])
> array.combine_maps(prometheus.exporter.redis.default.targets, [{"instance"="1.1.1.1", "testLabelKey" = "testLabelVal"}], ["instance"])
```

You can find more examples in the [tests][].

[tests]: https://github.com/grafana/alloy/blob/main/syntax/vm/vm_stdlib_test.go
[experimental]: https://grafana.com/docs/release-life-cycle/
51 changes: 51 additions & 0 deletions docs/sources/troubleshoot/support_bundle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
canonical: https://grafana.com/docs/alloy/latest/troubleshoot/support_bundle/
description: Learn how to generate a support bundle
title: Generate a support bundle
menuTitle: Generate a support bundle
weight: 300
---

<span class="badge docs-labels__stage docs-labels__item">Public preview</span>

# Generate a support bundle

{{< docs/public-preview product="Generate support bundle" >}}

The `/-/support?duration=N` endpoint returns a support bundle, a zip file that contains information
about a running {{< param "PRODUCT_NAME" >}} instance, and can be used as a baseline of information when trying
to debug an issue.

This feature is not covered by our [backward-compatibility][backward-compatibility] guarantees.

{{< admonition type="note" >}}
This endpoint is enabled by default, but may be disabled using the `--disable-support-bundle` runtime flag.
{{< /admonition >}}

The duration parameter is optional, must be less than or equal to the
configured HTTP server write timeout, and if not provided, defaults to it.
The endpoint is only exposed to the {{< param "PRODUCT_NAME" >}} HTTP server listen address, which
defaults to `localhost:12345`.

The support bundle contains all information in plain text, so you can
inspect it before sharing to verify that no sensitive information has leaked.

In addition, you can inspect the [supportbundle implementation](https://github.com/grafana/alloy/tree/internal/service/http/supportbundle.go)
to verify the code used to generate these bundles.

A support bundle contains the following data:
* `alloy-components.json` contains information about the [components][components] running on this {{< param "PRODUCT_NAME" >}} instance, generated by the
`/api/v0/web/components` endpoint.
* `alloy-logs.txt` contains the logs during the bundle generation.
* `alloy-metadata.yaml` contains the {{< param "PRODUCT_NAME" >}} build version and the installation's operating system, architecture, and uptime.
* `alloy-metrics.txt` contains a snapshot of the internal metrics for {{< param "PRODUCT_NAME" >}}.
* `alloy-peers.json` contains information about the identified cluster peers of this {{< param "PRODUCT_NAME" >}} instance, generated by the
`/api/v0/web/peers` endpoint.
* `alloy-runtime-flags.txt` contains the values of the runtime flags available in {{< param "PRODUCT_NAME" >}}.
* The `pprof/` directory contains Go runtime profiling data (CPU, heap, goroutine, mutex, block profiles) as exported by the pprof package.
Refer to the [profile][profile] documentation for more details on how to use this information.

[profile]: ../profile
[components]: ../../get-started/components/
[alloy-repo]: https://github.com/grafana/alloy/issues
[backward-compatibility]: ../../introduction/backward-compatibility
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,8 @@ require (
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.7.0 // indirect
)

require github.com/mackerelio/go-osstat v0.2.5

// NOTE: replace directives below must always be *temporary*.
//
// Adding a replace directive to change a module to a fork of a module will
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,8 @@ github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c h1:VtwQ41oftZwlMn
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE=
github.com/lyft/protoc-gen-validate v0.0.0-20180911180927-64fcb82c878e/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/mackerelio/go-osstat v0.2.5 h1:+MqTbZUhoIt4m8qzkVoXUJg1EuifwlAJSk4Yl2GXh+o=
github.com/mackerelio/go-osstat v0.2.5/go.mod h1:atxwWF+POUZcdtR1wnsUcQxTytoHG4uhl2AKKzrOajY=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
Expand Down
23 changes: 20 additions & 3 deletions internal/alloycli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/grafana/ckit/peer"
"github.com/prometheus/client_golang/prometheus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.opentelemetry.io/otel"
"golang.org/x/exp/maps"

Expand Down Expand Up @@ -64,6 +65,7 @@ func runCommand() *cobra.Command {
clusterAdvInterfaces: advertise.DefaultInterfaces,
clusterMaxJoinPeers: 5,
clusterRejoinInterval: 60 * time.Second,
disableSupportBundle: false,
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -100,7 +102,7 @@ depending on the nature of the reload error.
SilenceUsage: true,

RunE: func(cmd *cobra.Command, args []string) error {
return r.Run(args[0])
return r.Run(cmd, args[0])
},
}

Expand All @@ -111,6 +113,8 @@ depending on the nature of the reload error.
cmd.Flags().StringVar(&r.uiPrefix, "server.http.ui-path-prefix", r.uiPrefix, "Prefix to serve the HTTP UI at")
cmd.Flags().
BoolVar(&r.enablePprof, "server.http.enable-pprof", r.enablePprof, "Enable /debug/pprof profiling endpoints.")
cmd.Flags().
BoolVar(&r.disableSupportBundle, "server.http.disable-support-bundle", r.disableSupportBundle, "Disable /-/support support bundle retrieval.")

// Cluster flags
cmd.Flags().
Expand Down Expand Up @@ -184,9 +188,10 @@ type alloyRun struct {
configBypassConversionErrors bool
configExtraArgs string
enableCommunityComps bool
disableSupportBundle bool
}

func (fr *alloyRun) Run(configPath string) error {
func (fr *alloyRun) Run(cmd *cobra.Command, configPath string) error {
var wg sync.WaitGroup
defer wg.Wait()

Expand Down Expand Up @@ -275,8 +280,15 @@ func (fr *alloyRun) Run(configPath string) error {
return err
}

runtimeFlags := []string{}
if !fr.disableSupportBundle {
cmd.Flags().VisitAll(func(f *pflag.Flag) {
runtimeFlags = append(runtimeFlags, fmt.Sprintf("%s=%s", f.Name, f.Value.String()))
})
}

httpService := httpservice.New(httpservice.Options{
Logger: log.With(l, "service", "http"),
Logger: l,
Tracer: t,
Gatherer: prometheus.DefaultGatherer,

Expand All @@ -286,6 +298,11 @@ func (fr *alloyRun) Run(configPath string) error {
HTTPListenAddr: fr.httpListenAddr,
MemoryListenAddr: fr.inMemoryAddr,
EnablePProf: fr.enablePprof,
MinStability: fr.minStability,
BundleContext: httpservice.SupportBundleContext{
RuntimeFlags: runtimeFlags,
DisableSupportBundle: fr.disableSupportBundle,
},
})

remoteCfgService, err := remotecfgservice.New(remotecfgservice.Options{
Expand Down
24 changes: 23 additions & 1 deletion internal/runtime/internal/controller/component_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/go-kit/log"
"github.com/grafana/alloy/internal/featuregate"
"github.com/grafana/alloy/internal/runtime/internal/dag"
"github.com/grafana/alloy/internal/runtime/logging/level"
"github.com/grafana/alloy/syntax/ast"
Expand All @@ -18,6 +19,17 @@ import (
// will be (field_a, field_b, field_c).
type Traversal []*ast.Ident

// String returns a dot-separated string representation of the field names in the traversal.
// For example, a traversal of fields [field_a, field_b, field_c] returns "field_a.field_b.field_c".
// Returns an empty string if the traversal contains no fields.
func (t Traversal) String() string {
var fieldNames []string
for _, field := range t {
fieldNames = append(fieldNames, field.Name)
}
return strings.Join(fieldNames, ".")
}

// Reference describes an Alloy expression reference to a BlockNode.
type Reference struct {
Target BlockNode // BlockNode being referenced
Expand All @@ -29,7 +41,7 @@ type Reference struct {

// ComponentReferences returns the list of references a component is making to
// other components.
func ComponentReferences(cn dag.Node, g *dag.Graph, l log.Logger, scope *vm.Scope) ([]Reference, diag.Diagnostics) {
func ComponentReferences(cn dag.Node, g *dag.Graph, l log.Logger, scope *vm.Scope, minStability featuregate.Stability) ([]Reference, diag.Diagnostics) {
var (
traversals []Traversal

Expand Down Expand Up @@ -63,6 +75,16 @@ func ComponentReferences(cn dag.Node, g *dag.Graph, l log.Logger, scope *vm.Scop
refs = append(refs, ref)
} else if scope.IsStdlibDeprecated(t[0].Name) {
level.Warn(l).Log("msg", "this stdlib function is deprecated; please refer to the documentation for updated usage and alternatives", "function", t[0].Name)
} else if funcName := t.String(); scope.IsStdlibExperimental(funcName) {
if err := featuregate.CheckAllowed(featuregate.StabilityExperimental, minStability, funcName); err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.SeverityLevelError,
Message: err.Error(),
StartPos: ast.StartPos(t[0]).Position(),
EndPos: ast.StartPos(t[len(t)-1]).Position(),
})
continue
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/runtime/internal/controller/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func (l *Loader) wireGraphEdges(g *dag.Graph) diag.Diagnostics {

// Finally, wire component references.
l.cache.mut.RLock()
refs, nodeDiags := ComponentReferences(n, g, l.log, l.cache.scope)
refs, nodeDiags := ComponentReferences(n, g, l.log, l.cache.scope, l.globals.MinStability)
l.cache.mut.RUnlock()
for _, ref := range refs {
g.AddEdge(dag.Edge{From: n, To: ref.Target})
Expand Down
Loading

0 comments on commit 377fe47

Please sign in to comment.