Skip to content

Commit

Permalink
Option to set fixed app id
Browse files Browse the repository at this point in the history
  • Loading branch information
pondzix committed Dec 12, 2024
1 parent 4640977 commit e24778d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ object SdkEvent {
private def eventFromColPayload(
p: CollectorPayload,
fallbackEid: UUID,
enrichments: Option[Enrichments]
enrichments: Option[Enrichments],
fixedAppId: Option[String]
): List[Event] =
p.payload.map { el =>
val evnt = Some(el.e match {
Expand Down Expand Up @@ -96,7 +97,7 @@ object SdkEvent {
val deprecatedFields = enrichments.flatMap(_.deprecatedFields)

Event(
app_id = el.app.aid,
app_id = fixedAppId.orElse(el.app.aid),
platform = Some(el.app.p),
collector_tstamp = p.context.timestamp,
dvce_created_tstamp = el.dt.flatMap(_.dtm),
Expand Down Expand Up @@ -242,9 +243,10 @@ object SdkEvent {
now: Instant,
frequencies: EventFrequencies,
contexts: Context.ContextsConfig,
generateEnrichments: Boolean = false
generateEnrichments: Boolean = false,
fixedAppId: Option[String] = None
): Gen[List[Event]] =
genPair(eventPerPayloadMin, eventPerPayloadMax, now, frequencies, contexts, generateEnrichments).map(
genPair(eventPerPayloadMin, eventPerPayloadMax, now, frequencies, contexts, generateEnrichments, fixedAppId).map(
_._2
)

Expand All @@ -258,7 +260,8 @@ object SdkEvent {
now: Instant,
frequencies: EventFrequencies,
contexts: Context.ContextsConfig,
generateEnrichments: Boolean
generateEnrichments: Boolean,
fixedAppId: Option[String]
): Gen[(CollectorPayload, List[Event])] =
for {
cp <- CollectorPayload.genDup(
Expand All @@ -274,20 +277,21 @@ object SdkEvent {
)
enrichments <- if (generateEnrichments) Enrichments.gen.map(Some(_)) else Gen.const(None)
eid <- Gen.uuid
} yield (cp, eventFromColPayload(cp, eid, enrichments))
} yield (cp, eventFromColPayload(cp, eid, enrichments, fixedAppId))

def genPair(
eventPerPayloadMin: Int,
eventPerPayloadMax: Int,
now: Instant,
frequencies: EventFrequencies,
contexts: Context.ContextsConfig,
generateEnrichments: Boolean
generateEnrichments: Boolean,
fixedAppId: Option[String]
): Gen[(CollectorPayload, List[Event])] =
for {
cp <- CollectorPayload.gen(eventPerPayloadMin, eventPerPayloadMax, now, frequencies, contexts)
enrichments <- if (generateEnrichments) Enrichments.gen.map(Some(_)) else Gen.const(None)
eid <- Gen.uuid
} yield (cp, eventFromColPayload(cp, eid, enrichments))
} yield (cp, eventFromColPayload(cp, eid, enrichments, fixedAppId))

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ final case class Config(
withEnrichedJson: Boolean,
payloadsPerFile: Int,
duplicates: Option[Config.Duplicates],
fixedAppId: Option[String],
timestamps: Config.Timestamps,
eventFrequencies: EventFrequencies,
contexts: Context.ContextsConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ object Main extends IOApp {
time,
config.eventFrequencies,
config.contexts,
config.generateEnrichments
config.generateEnrichments,
config.fixedAppId
),
rng
),
Expand Down Expand Up @@ -123,7 +124,8 @@ object Main extends IOApp {
time,
config.eventFrequencies,
config.contexts,
config.generateEnrichments
config.generateEnrichments,
config.fixedAppId
),
rng
),
Expand Down

0 comments on commit e24778d

Please sign in to comment.