Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set maxBytes in the NsqSink #354

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,30 @@ import com.snowplowanalytics.snowplow.collector.core.model.Sinks

object Run {

type MkSinks[F[_], SinkConfig] = Config.Streams[SinkConfig] => Resource[F, Sinks[F]]

type TelemetryInfo[SinkConfig] = Config[SinkConfig] => Telemetry.TelemetryInfo

implicit private def logger[F[_]: Sync] = Slf4jLogger.getLogger[F]

def fromCli[F[_]: Async: Tracking, SinkConfig: Decoder](
appInfo: AppInfo,
mkSinks: Config.Streams[SinkConfig] => Resource[F, Sinks[F]],
telemetryInfo: Config[SinkConfig] => Telemetry.TelemetryInfo
mkSinks: MkSinks[F, SinkConfig],
telemetryInfo: TelemetryInfo[SinkConfig]
): Opts[F[ExitCode]] = {
val configPath = Opts.option[Path]("config", "Path to HOCON configuration (optional)", "c", "config.hocon").orNone
configPath.map(fromPath[F, SinkConfig](appInfo, mkSinks, telemetryInfo, _))
}

private def fromPath[F[_]: Async: Tracking, SinkConfig: Decoder](
appInfo: AppInfo,
mkSinks: Config.Streams[SinkConfig] => Resource[F, Sinks[F]],
telemetryInfo: Config[SinkConfig] => Telemetry.TelemetryInfo,
mkSinks: MkSinks[F, SinkConfig],
telemetryInfo: TelemetryInfo[SinkConfig],
path: Option[Path]
): F[ExitCode] = {
val eitherT = for {
config <- ConfigParser.fromPath[F, SinkConfig](path)
_ <- EitherT.right[ExitCode](fromConfig(appInfo, mkSinks, config, telemetryInfo))
_ <- EitherT.right[ExitCode](fromConfig(appInfo, mkSinks, telemetryInfo, config))
} yield ExitCode.Success

eitherT.merge.handleErrorWith { e =>
Expand All @@ -55,9 +59,9 @@ object Run {

private def fromConfig[F[_]: Async: Tracking, SinkConfig](
appInfo: AppInfo,
mkSinks: Config.Streams[SinkConfig] => Resource[F, Sinks[F]],
config: Config[SinkConfig],
telemetryInfo: Config[SinkConfig] => Telemetry.TelemetryInfo
mkSinks: MkSinks[F, SinkConfig],
telemetryInfo: TelemetryInfo[SinkConfig],
config: Config[SinkConfig]
): F[ExitCode] = {
val resources = for {
sinks <- mkSinks(config.streams)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ object NsqCollector extends App[NsqSinkConfig](BuildInfo) {
override def mkSinks(config: Config.Streams[NsqSinkConfig]): Resource[IO, Sinks[IO]] =
for {
good <- NsqSink.create[IO](
config.sink.maxBytes,
config.sink,
config.good
)
bad <- NsqSink.create[IO](
config.sink.maxBytes,
config.sink,
config.bad
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ class NsqSink[F[_]: Sync] private (
object NsqSink {

def create[F[_]: Sync](
maxBytes: Int,
nsqConfig: NsqSinkConfig,
topicName: String
): Resource[F, NsqSink[F]] =
Resource.make(
Sync[F].delay(
// MaxBytes is never used but is required by the sink interface definition,
// So just pass any int val in.
new NsqSink(0, nsqConfig, topicName)
new NsqSink(maxBytes, nsqConfig, topicName)
)
)(sink => Sync[F].delay(sink.shutdown()))
}
Loading