-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/module_id_fail' into module_id_fail
- Loading branch information
Showing
84 changed files
with
1,447 additions
and
716 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
Oops, something went wrong.