Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/module_id_fail' into module_id_fail
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdurham committed Oct 16, 2023
2 parents e69db8c + e5588be commit acaae50
Show file tree
Hide file tree
Showing 84 changed files with 1,447 additions and 716 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/check-versioned-files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test Versioned Files
on: pull_request
jobs:
regenerate-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Regenerate versioned files
run: |
make generate-versioned-files
if ! git diff --exit-code; then
echo "Newly generated versioned files differ from those checked in. Make sure to only update the templates manually and run 'make generate-versioned-files'!" >&2
exit 1
fi
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ internal API changes are not present.
Main (unreleased)
-----------------

### Breaking changes

- Remove `otelcol.exporter.jaeger` component (@hainenber)

### Features

- Added a new `stage.decolorize` stage to `loki.process` component which
allows to strip ANSI color codes from the log lines. (@thampiotr)

- Added a new `stage.sampling` stage to `loki.process` component which
allows to only process a fraction of logs and drop the rest. (@thampiotr)

- Added a new `stage.eventlogmessage` stage to `loki.process` component which
allows to extract data from Windows Event Log. (@thampiotr)

### Bugfixes

- Fixed an issue where `loki.process` validation for stage `metric.counter` was
Expand All @@ -27,6 +37,14 @@ Main (unreleased)

- The `loki.write` WAL now has snappy compression enabled by default. (@thepalbi)

v0.37.1 (2023-10-10)
-----------------

### Bugfixes

- Fix the initialization of the default namespaces map for the operator and the
loki.source.kubernetes component. (@wildum)

v0.37.0 (2023-10-10)
-----------------

Expand Down Expand Up @@ -196,6 +214,8 @@ v0.37.0 (2023-10-10)
- Fix initialization of the RAPL collector for the node_exporter integration
and the prometheus.exporter.unix component. (@marctc)

- Set instrumentation scope attribute for traces emitted by Flow component. (@hainenber)

### Other changes

- Use Go 1.21.1 for builds. (@rfratto)
Expand Down
32 changes: 20 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@
##
## Targets for generating assets:
##
## generate Generate everything.
## generate-crds Generate Grafana Agent Operator CRDs ands its documentation.
## generate-drone Generate the Drone YAML from Jsonnet.
## generate-helm-docs Generate Helm chart documentation.
## generate-helm-tests Generate Helm chart tests.
## generate-manifests Generate production/kubernetes YAML manifests.
## generate-dashboards Generate dashboards in example/docker-compose after
## changing Jsonnet.
## generate-protos Generate protobuf files.
## generate-ui Generate the UI assets.
## generate Generate everything.
## generate-crds Generate Grafana Agent Operator CRDs ands its documentation.
## generate-drone Generate the Drone YAML from Jsonnet.
## generate-helm-docs Generate Helm chart documentation.
## generate-helm-tests Generate Helm chart tests.
## generate-manifests Generate production/kubernetes YAML manifests.
## generate-dashboards Generate dashboards in example/docker-compose after
## changing Jsonnet.
## generate-protos Generate protobuf files.
## generate-ui Generate the UI assets.
## generate-versioned-files Generate versioned files.
##
## Other targets:
##
Expand Down Expand Up @@ -280,8 +281,8 @@ smoke-image:
# Targets for generating assets
#

.PHONY: generate generate-crds generate-drone generate-helm-docs generate-helm-tests generate-manifests generate-dashboards generate-protos generate-ui
generate: generate-crds generate-drone generate-helm-docs generate-helm-tests generate-manifests generate-dashboards generate-protos generate-ui
.PHONY: generate generate-crds generate-drone generate-helm-docs generate-helm-tests generate-manifests generate-dashboards generate-protos generate-ui generate-versioned-files
generate: generate-crds generate-drone generate-helm-docs generate-helm-tests generate-manifests generate-dashboards generate-protos generate-ui generate-versioned-files

generate-crds:
ifeq ($(USE_CONTAINER),1)
Expand Down Expand Up @@ -337,6 +338,13 @@ else
cd ./web/ui && yarn --network-timeout=1200000 && yarn run build
endif

generate-versioned-files:
ifeq ($(USE_CONTAINER),1)
$(RERUN_IN_CONTAINER)
else
sh ./tools/gen-versioned-files/gen-versioned-files.sh
endif

#
# Other targets
#
Expand Down
1 change: 0 additions & 1 deletion component/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import (
_ "github.com/grafana/agent/component/otelcol/connector/servicegraph" // Import otelcol.connector.servicegraph
_ "github.com/grafana/agent/component/otelcol/connector/spanlogs" // Import otelcol.connector.spanlogs
_ "github.com/grafana/agent/component/otelcol/connector/spanmetrics" // Import otelcol.connector.spanmetrics
_ "github.com/grafana/agent/component/otelcol/exporter/jaeger" // Import otelcol.exporter.jaeger
_ "github.com/grafana/agent/component/otelcol/exporter/loadbalancing" // Import otelcol.exporter.loadbalancing
_ "github.com/grafana/agent/component/otelcol/exporter/logging" // Import otelcol.exporter.logging
_ "github.com/grafana/agent/component/otelcol/exporter/loki" // Import otelcol.exporter.loki
Expand Down
134 changes: 134 additions & 0 deletions component/loki/process/stages/eventlogmessage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package stages

import (
"fmt"
"strings"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/common/model"
)

const (
defaultSource = "message"
)

type EventLogMessageConfig struct {
Source string `river:"source,attr,optional"`
DropInvalidLabels bool `river:"drop_invalid_labels,attr,optional"`
OverwriteExisting bool `river:"overwrite_existing,attr,optional"`
}

func (e *EventLogMessageConfig) Validate() error {
if !model.LabelName(e.Source).IsValid() {
return fmt.Errorf(ErrInvalidLabelName, e.Source)
}
return nil
}

func (e *EventLogMessageConfig) SetToDefault() {
e.Source = defaultSource
}

type eventLogMessageStage struct {
cfg *EventLogMessageConfig
logger log.Logger
}

// Create a event log message stage, including validating any supplied configuration
func newEventLogMessageStage(logger log.Logger, cfg *EventLogMessageConfig) Stage {
return &eventLogMessageStage{
cfg: cfg,
logger: log.With(logger, "component", "stage", "type", "eventlogmessage"),
}
}

func (m *eventLogMessageStage) Run(in chan Entry) chan Entry {
out := make(chan Entry)
key := m.cfg.Source
go func() {
defer close(out)
for e := range in {
err := m.processEntry(e.Extracted, key)
if err != nil {
continue
}
out <- e
}
}()
return out
}

// Process a event log message from extracted with the specified key, adding additional
// entries into the extracted map
func (m *eventLogMessageStage) processEntry(extracted map[string]interface{}, key string) error {
value, ok := extracted[key]
if !ok {
if Debug {
level.Debug(m.logger).Log("msg", "source not in the extracted values", "source", key)
}
return nil
}
s, err := getString(value)
if err != nil {
level.Warn(m.logger).Log("msg", "invalid label value parsed", "value", value)
return err
}
lines := strings.Split(s, "\r\n")
for _, line := range lines {
parts := strings.SplitN(line, ":", 2)
if len(parts) < 2 {
level.Warn(m.logger).Log("msg", "invalid line parsed from message", "line", line)
continue
}
mkey := parts[0]
if !model.LabelName(mkey).IsValid() {
if m.cfg.DropInvalidLabels {
if Debug {
level.Debug(m.logger).Log("msg", "invalid label parsed from message", "key", mkey)
}
continue
}
mkey = SanitizeFullLabelName(mkey)
}
if _, ok := extracted[mkey]; ok && !m.cfg.OverwriteExisting {
level.Info(m.logger).Log("msg", "extracted key that already existed, appending _extracted to key",
"key", mkey)
mkey += "_extracted"
}
mval := strings.TrimSpace(parts[1])
if !model.LabelValue(mval).IsValid() {
if Debug {
level.Debug(m.logger).Log("msg", "invalid value parsed from message", "value", mval)
}
continue
}
extracted[mkey] = mval
}
if Debug {
level.Debug(m.logger).Log("msg", "extracted data debug in event_log_message stage",
"extracted data", fmt.Sprintf("%v", extracted))
}
return nil
}

func (m *eventLogMessageStage) Name() string {
return StageTypeEventLogMessage
}

// Sanitize a input string to convert it into a valid prometheus label
// TODO: switch to prometheus/prometheus/util/strutil/SanitizeFullLabelName
func SanitizeFullLabelName(input string) string {
if len(input) == 0 {
return "_"
}
var validSb strings.Builder
for i, b := range input {
if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || (b >= '0' && b <= '9' && i > 0)) {
validSb.WriteRune('_')
} else {
validSb.WriteRune(b)
}
}
return validSb.String()
}
Loading

0 comments on commit acaae50

Please sign in to comment.