@ -396,7 +396,7 @@ type QueueManager struct {
flushDeadline time . Duration
cfg config . QueueConfig
mcfg config . MetadataConfig
externalLabels labels . Label s
externalLabels [ ] labels . Label
relabelConfigs [ ] * relabel . Config
sendExemplars bool
sendNativeHistograms bool
@ -454,13 +454,19 @@ func NewQueueManager(
logger = log . NewNopLogger ( )
}
// Copy externalLabels into slice which we need for processExternalLabels.
extLabelsSlice := make ( [ ] labels . Label , 0 , externalLabels . Len ( ) )
externalLabels . Range ( func ( l labels . Label ) {
extLabelsSlice = append ( extLabelsSlice , l )
} )
logger = log . With ( logger , remoteName , client . Name ( ) , endpoint , client . Endpoint ( ) )
t := & QueueManager {
logger : logger ,
flushDeadline : flushDeadline ,
cfg : cfg ,
mcfg : mCfg ,
externalLabels : ext ernal Labels,
externalLabels : ext LabelsSlice ,
relabelConfigs : relabelConfigs ,
storeClient : client ,
sendExemplars : enableExemplarRemoteWrite ,
@ -769,8 +775,8 @@ func (t *QueueManager) StoreSeries(series []record.RefSeries, index int) {
t . seriesSegmentIndexes [ s . Ref ] = index
ls := processExternalLabels ( s . Labels , t . externalLabels )
lbls := relabel . Process ( ls , t . relabelConfigs ... )
if len ( lbls ) == 0 {
lbls , keep := relabel . Process ( ls , t . relabelConfigs ... )
if ! keep || lbls . IsEmpty ( ) {
t . droppedSeries [ s . Ref ] = struct { } { }
continue
}
@ -831,44 +837,33 @@ func (t *QueueManager) client() WriteClient {
}
func ( t * QueueManager ) internLabels ( lbls labels . Labels ) {
for i , l := range lbls {
lbls [ i ] . Name = t . interner . intern ( l . Name )
lbls [ i ] . Value = t . interner . intern ( l . Value )
}
lbls . InternStrings ( t . interner . intern )
}
func ( t * QueueManager ) releaseLabels ( ls labels . Labels ) {
for _ , l := range ls {
t . interner . release ( l . Name )
t . interner . release ( l . Value )
}
ls . ReleaseStrings ( t . interner . release )
}
// processExternalLabels merges externalLabels into ls. If ls contains
// a label in externalLabels, the value in ls wins.
func processExternalLabels ( ls , externalLabels labels . Labels ) labels . Labels {
i , j , result := 0 , 0 , make ( labels . Labels , 0 , len ( ls ) + len ( externalLabels ) )
for i < len ( ls ) && j < len ( externalLabels ) {
if ls [ i ] . Name < externalLabels [ j ] . Name {
result = append ( result , labels . Label {
Name : ls [ i ] . Name ,
Value : ls [ i ] . Value ,
} )
i ++
} else if ls [ i ] . Name > externalLabels [ j ] . Name {
result = append ( result , externalLabels [ j ] )
func processExternalLabels ( ls labels . Labels , externalLabels [ ] labels . Label ) labels . Labels {
b := labels . NewScratchBuilder ( ls . Len ( ) + len ( externalLabels ) )
j := 0
ls . Range ( func ( l labels . Label ) {
for j < len ( externalLabels ) && l . Name > externalLabels [ j ] . Name {
b . Add ( externalLabels [ j ] . Name , externalLabels [ j ] . Value )
j ++
} else {
result = append ( result , labels . Label {
Name : ls [ i ] . Name ,
Value : ls [ i ] . Value ,
} )
i ++
}
if j < len ( externalLabels ) && l . Name == externalLabels [ j ] . Name {
j ++
}
b . Add ( l . Name , l . Value )
} )
for ; j < len ( externalLabels ) ; j ++ {
b . Add ( externalLabels [ j ] . Name , externalLabels [ j ] . Value )
}
return append ( append ( result , ls [ i : ] ... ) , externalLabels [ j : ] ... )
return b . Labels ( )
}
func ( t * QueueManager ) updateShardsLoop ( ) {