-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow tracking kafka produce and consume offsets (#18)
This was the one remaining feature from the golang library that I haven't ported yet. Now it's done. It allows tracking Kafka offsets. Datadog uses this to detect lag and consumers that are offline and not reporting. After every publish, we push the last offset to Datadog. After every consume, we push the last read offset to Datadog. It can then calculate the offset and alert us on issues. --------- Co-authored-by: Matt Sutkowski <[email protected]>
- Loading branch information
1 parent
37f997f
commit ebab69b
Showing
7 changed files
with
188 additions
and
25 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
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,48 @@ | ||
defmodule Datadog.DataStreams.Aggregator.Offset do | ||
@moduledoc false | ||
|
||
defstruct offset: 0, | ||
timestamp: 0, | ||
type: :commit, | ||
tags: %{} | ||
|
||
@type type :: :commit | :produce | ||
|
||
@type t :: %__MODULE__{ | ||
offset: integer(), | ||
timestamp: non_neg_integer(), | ||
type: type(), | ||
tags: %{String.t() => any()} | ||
} | ||
|
||
@doc """ | ||
Creates a new offset map with the given offset and options | ||
""" | ||
@spec new(type(), integer(), non_neg_integer(), Keyword.t()) :: t() | ||
def new(type, offset, timestamp, opts \\ []) do | ||
%__MODULE__{ | ||
offset: offset, | ||
timestamp: timestamp, | ||
type: type, | ||
tags: Map.new(opts) | ||
} | ||
end | ||
|
||
@doc """ | ||
Updates an existing `#{__MODULE__}` where all properties except the | ||
`offset` match. If no match is found, we create a new one. | ||
""" | ||
@spec upsert([t()], t()) :: [t()] | ||
def upsert(offsets, %{tags: upsert_tags} = upsert_offset) do | ||
matching_index = | ||
Enum.find(offsets, fn %{tags: tags} -> | ||
match?(^tags, upsert_tags) | ||
end) | ||
|
||
if is_nil(matching_index) do | ||
offsets ++ [upsert_offset] | ||
else | ||
List.replace_at(offsets, matching_index, upsert_offset) | ||
end | ||
end | ||
end |
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