forked from Telefonica/prometheus-kafka-adapter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes Telefonica#75: allow labels to be hashed into topic partitions
- Loading branch information
1 parent
8722897
commit 60368ed
Showing
8 changed files
with
128 additions
and
9 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 |
---|---|---|
|
@@ -11,4 +11,5 @@ | |
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
/vendor | ||
/prometheus-kafka-adapter |
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
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,47 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"math" | ||
"sync" | ||
"time" | ||
|
||
"github.com/confluentinc/confluent-kafka-go/kafka" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var topicPartitionCount sync.Map | ||
|
||
type metaDataFetcher interface { | ||
GetMetadata(topic *string, allTopics bool, timeoutMs int) (*kafka.Metadata, error) | ||
} | ||
|
||
func syncTopicMetadata(ctx context.Context, producer metaDataFetcher) error { | ||
|
||
if err := processMetadata(producer); err != nil { | ||
return err | ||
} | ||
go func() { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
|
||
case <-time.After(kafkaMetadataInterval): | ||
if err := processMetadata(producer); err != nil { | ||
logrus.WithError(err).Error("could not fetch topic metadata") | ||
} | ||
} | ||
}() | ||
return nil | ||
} | ||
|
||
func processMetadata(producer metaDataFetcher) error { | ||
metadata, err := producer.GetMetadata(nil, true, int(math.Ceil(kafkaMetadataTimeout.Seconds()))) | ||
if err != nil { | ||
return err | ||
} | ||
for name, topic := range metadata.Topics { | ||
topicPartitionCount.Store(name, len(topic.Partitions)) | ||
} | ||
return nil | ||
} |