Skip to content

Commit 6cf6a40

Browse files
committed
Unfreeze build for BigQuery target
1 parent 0d3880f commit 6cf6a40

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/Logary.Tests/Targets.Baseline.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ let basicTests targetName confFac addTS =
113113
}
114114

115115
testCaseJob "log user upgraded plan message" <| job {
116-
let! targetApi, now = configure ()
116+
let! targetApi, _ = configure ()
117117
do! logMsgWaitAndShutdown targetApi (fun logAndWait -> logAndWait Messages.userUpgradedPlan)
118118
}
119119
]

src/targets/Logary.Targets.BigQuery/Targets_BigQuery.fs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,19 @@ let empty = BigQueryConf.create()
3636

3737
module internal Impl =
3838
open System
39-
open System.IO
4039
open Google.Apis.Bigquery.v2.Data
4140
open Logary.Internals.Chiron
4241
module E = Json.Encode
4342

4443
let tableSchema =
4544
let builder = TableSchemaBuilder()
46-
let field name typ mode = new TableFieldSchema(Name=name, Type=typ, Mode=mode)
45+
let field name typ mode = TableFieldSchema(Name=name, Type=typ, Mode=mode)
4746
let req name typ = field name typ "REQUIRED"
4847
let opt name typ = field name typ "NULLABLE"
4948
builder.Add(req "level" "INT64")
5049
builder.Add(opt "event" "STRING")
51-
builder.Add(opt "monetaryValue.amount" "NUMERIC")
52-
builder.Add(opt "monetaryValue.currency" "STRING")
50+
builder.Add(opt "money_amount" "NUMERIC")
51+
builder.Add(opt "money_currency" "STRING")
5352
builder.Add(req "name" "STRING")
5453
builder.Add(req "timestamp" "TIMESTAMP")
5554
/// JSON string
@@ -74,11 +73,11 @@ module internal Impl =
7473
let me = x.getAsOrThrow<EventMessage>()
7574
row.["event"] <- me.event
7675
if me.monetaryValue.IsSome then
77-
row.["monetaryValue.amount"] <- me.monetaryValue.Value.value.asFloat
78-
row.["monetaryValue.currency"] <- me.monetaryValue.Value.unit.name
76+
row.["money_amount"] <- me.monetaryValue.Value.value.asFloat
77+
row.["money_currency"] <- me.monetaryValue.Value.unit.name.Value
7978
else
80-
row.["monetaryValue.amount"] <- 0.
81-
row.["monetaryValue.currency"] <- "EUR"
79+
row.["money_amount"] <- 0.
80+
row.["money_currency"] <- "EUR"
8281
| _ -> ()
8382
row
8483

@@ -97,12 +96,16 @@ module internal Impl =
9796

9897
let rec initialise () =
9998
job {
99+
logger.debug "Starting BigQuery target"
100100
let! platform = Platform.InstanceAsync()
101+
logger.debug "Received platform information"
101102
let projectId = conf.projectId |> Option.defaultValue platform.ProjectId
102103
let client = BigQueryClient.Create(projectId)
103104
let dataset = client.GetOrCreateDataset(conf.dataset)
104105
let table = dataset.GetOrCreateTable(conf.table, tableSchema)
105106
do! maybeUpdate projectId dataset table tableSchema
107+
108+
logger.debug "Going into the Running state"
106109
return! running { table=table; client=client }
107110
}
108111

@@ -132,11 +135,18 @@ module internal Impl =
132135
}
133136

134137
api.shutdownCh ^=> fun ack ->
138+
logger.debug "Shutting down BigQuery target"
135139
Job.Scheduler.isolate (fun _ -> (state :> IDisposable).Dispose())
136140
>>=. ack *<= ()
137141
] :> Job<_>
138142

139-
initialise ()
143+
Job.catch (initialise ()) >>= function
144+
| Choice1Of2 () ->
145+
Job.unit ()
146+
| Choice2Of2 e ->
147+
printfn "%A" e
148+
Job.raises e
149+
140150

141151
/// Create a new BigQuery target
142152
[<CompiledName "Create">]

src/tests/Logary.Targets.BigQuery.Tests/Program.fs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ open Hopac
55
open Logary
66
open Logary.Tests
77
open Logary.Internals
8-
open Logary.Targets
98
open Logary.Targets.BigQuery
109
open System
1110
open System.IO
@@ -22,14 +21,14 @@ let bigQuery =
2221
let target =
2322
testList "big query" [
2423
TargetBaseline.basicTests "Google BigQuery" (fun name ->
25-
BigQuery.create bigQuery.Value name) true
24+
create bigQuery.Value name) true
2625

2726
testCaseJob "send" <| job {
2827
let ri = RuntimeInfo.ofServiceAndHost "bigquery-tests" "localhost"
29-
let targetConf = BigQuery.create bigQuery.Value "logary-bigquery"
28+
let targetConf = create bigQuery.Value "logary-bigquery"
3029
let! target = Target.create ri targetConf
3130

32-
for i in 0..20 do
31+
for _ in 0..20 do
3332
let! ack =
3433
let e = raisedExnWithInner "outer exception" (raisedExn "inner exception")
3534
let evt = Model.Event("thing happened at {blah}", None, level=Error)
@@ -47,4 +46,4 @@ let target =
4746
let main argv =
4847
let privKey = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bigquery-service-account.json")
4948
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", privKey)
50-
Tests.runTestsInAssembly defaultConfig argv
49+
runTestsInAssembly defaultConfig argv

0 commit comments

Comments
 (0)