Skip to content

Commit

Permalink
Merge branch 'main' into am-template-vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreixell authored Nov 16, 2023
2 parents 54b9d98 + 7e33d9c commit 38f01e4
Show file tree
Hide file tree
Showing 21 changed files with 1,273 additions and 312 deletions.
14 changes: 11 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Main (unreleased)

- `otelcol.processor.filter` - filters OTLP telemetry data using OpenTelemetry
Transformation Language (OTTL). (@hainenber)
- `otelcol.receiver.vcenter` - receives metrics telemetry data from vCenter. (@marctc)

- Agent Management: Introduce support for remotely managed external labels for logs. (@jcreixell)

Expand Down Expand Up @@ -94,10 +95,14 @@ Main (unreleased)

- Added support for replaying not sent data for `loki.write` when WAL is enabled. (@thepalbi)

- Make the result of 'discovery.kubelet' support pods that without ports, such as k8s control plane static pods. (@masonmei)

- Added support for unicode strings in `pyroscope.ebpf` python profiles. (@korniltsev)

- Improved resilience of graph evaluation in presence of slow components. (@thampiotr)

- Updated windows exporter to use prometheus-community/windows_exporter commit 1836cd1. (@mattdurham)

### Bugfixes

- Set exit code 1 on grafana-agentctl non-runnable command. (@fgouteroux)
Expand Down Expand Up @@ -146,6 +151,9 @@ Main (unreleased)
- Fix a bug which prevented Agent from running `otelcol.exporter.loadbalancing`
with a `routing_key` of `traceID`. (@ptodev)

- Added Kubernetes service resolver to static node's loadbalancing exporter
and to Flow's `otelcol.exporter.loadbalancing`. (@ptodev)

### Other changes

- Bump `mysqld_exporter` version to v0.15.0. (@marctc)
Expand All @@ -156,6 +164,9 @@ Main (unreleased)

- Change User-Agent header for outbound requests to include agent-mode, goos, and deployment mode. Example `GrafanaAgent/v0.38.0 (flow; linux; docker)` (@captncraig)

- `loki.source.windowsevent` and `loki.source.*` changed to use a more robust positions file to prevent corruption on reboots when writing
the positions file. (@mattdurham)

v0.37.4 (2023-11-06)
-----------------

Expand All @@ -169,9 +180,6 @@ v0.37.4 (2023-11-06)
- Fix a bug where reloading the configuration of a `loki.write` component lead
to a panic. (@tpaschalis)

- Added Kubernetes service resolver to static node's loadbalancing exporter
and to Flow's `otelcol.exporter.loadbalancing`. (@ptodev)

v0.37.3 (2023-10-26)
-----------------

Expand Down
1 change: 1 addition & 0 deletions component/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import (
_ "github.com/grafana/agent/component/otelcol/receiver/opencensus" // Import otelcol.receiver.opencensus
_ "github.com/grafana/agent/component/otelcol/receiver/otlp" // Import otelcol.receiver.otlp
_ "github.com/grafana/agent/component/otelcol/receiver/prometheus" // Import otelcol.receiver.prometheus
_ "github.com/grafana/agent/component/otelcol/receiver/vcenter" // Import otelcol.receiver.vcenter
_ "github.com/grafana/agent/component/otelcol/receiver/zipkin" // Import otelcol.receiver.zipkin
_ "github.com/grafana/agent/component/prometheus/exporter/agent" // Import prometheus.exporter.agent
_ "github.com/grafana/agent/component/prometheus/exporter/apache" // Import prometheus.exporter.apache
Expand Down
17 changes: 3 additions & 14 deletions component/common/loki/positions/write_positions_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,18 @@ package positions
// same place in case of a restart.

import (
"os"
"path/filepath"

"bytes"
"github.com/natefinch/atomic"
yaml "gopkg.in/yaml.v2"
)

// writePositionFile is a fallback for Windows because renameio does not support Windows.
// See https://github.com/google/renameio#windows-support
func writePositionFile(filename string, positions map[Entry]string) error {
buf, err := yaml.Marshal(File{
Positions: positions,
})
if err != nil {
return err
}
return atomic.WriteFile(filename, bytes.NewReader(buf))

target := filepath.Clean(filename)
temp := target + "-new"

err = os.WriteFile(temp, buf, os.FileMode(positionFileMode))
if err != nil {
return err
}

return os.Rename(temp, target)
}
40 changes: 40 additions & 0 deletions component/discovery/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
podNameLabel = metaLabelPrefix + "pod_name"
podIPLabel = metaLabelPrefix + "pod_ip"
podContainerNameLabel = metaLabelPrefix + "pod_container_name"
podContainerIDLabel = metaLabelPrefix + "pod_container_id"
podContainerImageLabel = metaLabelPrefix + "pod_container_image"
podContainerPortNameLabel = metaLabelPrefix + "pod_container_port_name"
podContainerPortNumberLabel = metaLabelPrefix + "pod_container_port_number"
Expand Down Expand Up @@ -214,13 +215,35 @@ func (d *Discovery) buildPodTargetGroup(pod v1.Pod) *targetgroup.Group {
containers := append(pod.Spec.Containers, pod.Spec.InitContainers...)
for i, c := range containers {
isInit := i >= len(pod.Spec.Containers)
cStatuses := &pod.Status.ContainerStatuses
if isInit {
cStatuses = &pod.Status.InitContainerStatuses
}
cID := d.findPodContainerID(cStatuses, c.Name)

// If no ports are defined for the container, create an anonymous
// target per container.
if len(c.Ports) == 0 {
// We don't have a port so we just set the address label to the pod IP.
// The user has to add a port manually.
tg.Targets = append(tg.Targets, model.LabelSet{
model.AddressLabel: lv(pod.Status.PodIP),
podContainerNameLabel: lv(c.Name),
podContainerIDLabel: lv(cID),
podContainerImageLabel: lv(c.Image),
podContainerIsInit: lv(strconv.FormatBool(isInit)),
})
continue
}

for _, port := range c.Ports {
ports := strconv.FormatUint(uint64(port.ContainerPort), 10)
addr := net.JoinHostPort(pod.Status.PodIP, ports)

tg.Targets = append(tg.Targets, model.LabelSet{
model.AddressLabel: lv(addr),
podContainerNameLabel: lv(c.Name),
podContainerIDLabel: lv(cID),
podContainerImageLabel: lv(c.Image),
podContainerPortNumberLabel: lv(ports),
podContainerPortNameLabel: lv(port.Name),
Expand All @@ -233,6 +256,23 @@ func (d *Discovery) buildPodTargetGroup(pod v1.Pod) *targetgroup.Group {
return tg
}

func (p *Discovery) findPodContainerStatus(statuses *[]v1.ContainerStatus, containerName string) (*v1.ContainerStatus, error) {
for _, s := range *statuses {
if s.Name == containerName {
return &s, nil
}
}
return nil, fmt.Errorf("cannot find container with name %v", containerName)
}

func (p *Discovery) findPodContainerID(statuses *[]v1.ContainerStatus, containerName string) string {
cStatus, err := p.findPodContainerStatus(statuses, containerName)
if err != nil {
return ""
}
return cStatus.ContainerID
}

func (d *Discovery) podInTargetNamespaces(pod v1.Pod) bool {
for _, ns := range d.targetNamespaces {
if pod.Namespace == ns {
Expand Down
17 changes: 17 additions & 0 deletions component/discovery/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,20 @@ func newPod(name, namespace string) v1.Pod {
},
}
}

func TestDiscoveryPodWithoutPod(t *testing.T) {
pod1 := newPod("pod-1", "namespace-1")
pod2 := newPod("pod-2", "namespace-2")
pod1.Spec.Containers[0].Ports = []v1.ContainerPort{}

podList1 := v1.PodList{
Items: []v1.Pod{pod1, pod2},
}

kubeletDiscovery, err := NewKubeletDiscovery(DefaultConfig)
require.NoError(t, err)

_, err = kubeletDiscovery.refresh(podList1)
require.NoError(t, err)
require.Len(t, kubeletDiscovery.discoveredPodSources, 2)
}
89 changes: 89 additions & 0 deletions component/loki/source/windowsevent/bookmark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//go:build windows
// +build windows

// This code is copied from Promtail v1.6.2-0.20231004111112-07cbef92268a with minor changes.

package windowsevent

import (
"bytes"
"errors"
"github.com/natefinch/atomic"
"io"
"io/fs"
"os"

"github.com/grafana/loki/clients/pkg/promtail/targets/windows/win_eventlog"
)

type bookMark struct {
handle win_eventlog.EvtHandle
isNew bool
path string
buf []byte
}

// newBookMark creates a new windows event bookmark.
// The bookmark will be saved at the given path. Use save to save the current position for a given event.
func newBookMark(path string) (*bookMark, error) {
// 16kb buffer for rendering bookmark
buf := make([]byte, 16<<10)

_, err := os.Stat(path)
// creates a new bookmark file if none exists.
if errors.Is(err, fs.ErrNotExist) {
_, err := os.Create(path)
if err != nil {
return nil, err
}
bm, err := win_eventlog.CreateBookmark("")
if err != nil {
return nil, err
}
return &bookMark{
handle: bm,
path: path,
isNew: true,
buf: buf,
}, nil
}
if err != nil {
return nil, err
}
// otherwise open the current one.
file, err := os.OpenFile(path, os.O_RDWR, 0666)
if err != nil {
return nil, err
}
fileContent, err := io.ReadAll(file)
if err != nil {
return nil, err
}
fileString := string(fileContent)
// load the current bookmark.
bm, err := win_eventlog.CreateBookmark(fileString)
if err != nil {
// If we errored likely due to incorrect data then create a blank one
bm, err = win_eventlog.CreateBookmark("")
fileString = ""
// This should never fail but just in case.
if err != nil {
return nil, err
}
}
return &bookMark{
handle: bm,
path: path,
isNew: fileString == "",
buf: buf,
}, nil
}

// save Saves the bookmark at the current event position.
func (b *bookMark) save(event win_eventlog.EvtHandle) error {
newBookmark, err := win_eventlog.UpdateBookmark(b.handle, event, b.buf)
if err != nil {
return err
}
return atomic.WriteFile(b.path, bytes.NewReader([]byte(newBookmark)))
}
5 changes: 2 additions & 3 deletions component/loki/source/windowsevent/component_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/grafana/agent/component/common/loki/utils"
"github.com/grafana/loki/clients/pkg/promtail/api"
"github.com/grafana/loki/clients/pkg/promtail/scrapeconfig"
"github.com/grafana/loki/clients/pkg/promtail/targets/windows"
)

func init() {
Expand All @@ -35,7 +34,7 @@ type Component struct {

mut sync.RWMutex
args Arguments
target *windows.Target
target *Target
handle *handler
receivers []loki.LogsReceiver
}
Expand Down Expand Up @@ -123,7 +122,7 @@ func (c *Component) Update(args component.Arguments) error {
_ = f.Close()
}

winTarget, err := windows.New(c.opts.Logger, c.handle, nil, convertConfig(newArgs))
winTarget, err := NewTarget(c.opts.Logger, c.handle, nil, convertConfig(newArgs))
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 38f01e4

Please sign in to comment.