@@ -36,27 +36,25 @@ type TruncateConfig struct {
3636}
3737
3838type RuleConfig struct {
39- Limit units.Base2Bytes `alloy:"limit,attr"`
40- Suffix string `alloy:"suffix,attr,optional"`
41- Sources []string `alloy:"sources,attr,optional"`
42- SourceType TruncateSourceType `alloy:"source_type,attr,optional"`
39+ Limit units.Base2Bytes `alloy:"limit,attr"`
40+ Suffix string `alloy:"suffix,attr,optional"`
41+ Sources []string `alloy:"sources,attr,optional"`
42+ SourceType SourceType `alloy:"source_type,attr,optional"`
4343
4444 effectiveLimit units.Base2Bytes
4545}
4646
4747var (
48- _ encoding.TextMarshaler = TruncateSourceType ("" )
49- _ encoding.TextUnmarshaler = (* TruncateSourceType )(nil )
48+ _ encoding.TextMarshaler = SourceType ("" )
49+ _ encoding.TextUnmarshaler = (* SourceType )(nil )
5050)
5151
52- type TruncateSourceType string
53-
5452// UnmarshalText implements encoding.TextUnmarshaler.
55- func (t * TruncateSourceType ) UnmarshalText (text []byte ) error {
53+ func (t * SourceType ) UnmarshalText (text []byte ) error {
5654 str := string (text )
5755 switch str {
58- case string (TruncateSourceLine ), string (TruncateSourceLabel ), string (TruncateSourceStructuredMetadata ), string (TruncateSourceExtractedMap ):
59- * t = TruncateSourceType (str )
56+ case string (SourceTypeLine ), string (SourceTypeLabel ), string (SourceTypeStructuredMetadata ), string (SourceTypeExtractedMap ):
57+ * t = SourceType (str )
6058 default :
6159 return fmt .Errorf ("unknown source_type: %s" , str )
6260 }
@@ -65,17 +63,10 @@ func (t *TruncateSourceType) UnmarshalText(text []byte) error {
6563}
6664
6765// MarshalText implements encoding.TextMarshaler.
68- func (t TruncateSourceType ) MarshalText () (text []byte , err error ) {
66+ func (t SourceType ) MarshalText () (text []byte , err error ) {
6967 return []byte (t ), nil
7068}
7169
72- const (
73- TruncateSourceLine TruncateSourceType = "line"
74- TruncateSourceLabel TruncateSourceType = "label"
75- TruncateSourceStructuredMetadata TruncateSourceType = "structured_metadata"
76- TruncateSourceExtractedMap TruncateSourceType = "extracted"
77- )
78-
7970// validateTruncateConfig validates the TruncateConfig for the truncateStage
8071func validateTruncateConfig (cfg * TruncateConfig ) error {
8172 if len (cfg .Rules ) == 0 {
@@ -90,10 +81,10 @@ func validateTruncateConfig(cfg *TruncateConfig) error {
9081 }
9182
9283 if r .SourceType == "" {
93- r .SourceType = TruncateSourceLine
84+ r .SourceType = SourceTypeLine
9485 }
9586
96- if r .SourceType == TruncateSourceLine && len (r .Sources ) > 0 {
87+ if r .SourceType == SourceTypeLine && len (r .Sources ) > 0 {
9788 return errors .New (errSourcesForLine )
9889 }
9990
@@ -138,7 +129,7 @@ func (m *truncateStage) Run(in chan Entry) chan Entry {
138129 truncated := map [string ]struct {}{}
139130 for _ , r := range m .cfg .Rules {
140131 switch r .SourceType {
141- case TruncateSourceLine :
132+ case SourceTypeLine :
142133 if len (e .Line ) > int (r .effectiveLimit ) {
143134 e .Line = e .Line [:r .effectiveLimit ] + r .Suffix
144135 markTruncated (m .truncatedCount , truncated , truncateLineField )
@@ -147,7 +138,7 @@ func (m *truncateStage) Run(in chan Entry) chan Entry {
147138 level .Debug (m .logger ).Log ("msg" , "line has been truncated" , "limit" , r .effectiveLimit , "truncated_line" , e .Line )
148139 }
149140 }
150- case TruncateSourceLabel :
141+ case SourceTypeLabel :
151142 if len (r .Sources ) > 0 {
152143 for _ , source := range r .Sources {
153144 name := model .LabelName (source )
@@ -160,7 +151,7 @@ func (m *truncateStage) Run(in chan Entry) chan Entry {
160151 m .tryTruncateLabel (r , e .Labels , k , v , truncated )
161152 }
162153 }
163- case TruncateSourceStructuredMetadata :
154+ case SourceTypeStructuredMetadata :
164155 if len (r .Sources ) > 0 {
165156 for i , v := range e .StructuredMetadata {
166157 if slices .Contains (r .Sources , v .Name ) {
@@ -174,7 +165,7 @@ func (m *truncateStage) Run(in chan Entry) chan Entry {
174165 e .StructuredMetadata [i ] = m .tryTruncateStructuredMetadata (r , v , truncated )
175166 }
176167 }
177- case TruncateSourceExtractedMap :
168+ case SourceTypeExtractedMap :
178169 if len (r .Sources ) > 0 {
179170 for _ , source := range r .Sources {
180171 if v , ok := e .Extracted [source ]; ok {
0 commit comments