Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
419cb6a5
Commit
419cb6a5
authored
6 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
[enh] pilot Monitoring annotations using constants
parent
31b62d6a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/debug/MonitorLokiExecutionTime.ts
+16
-13
16 additions, 13 deletions
app/lib/debug/MonitorLokiExecutionTime.ts
app/lib/debug/MonitorSQLExecutionTime.ts
+15
-12
15 additions, 12 deletions
app/lib/debug/MonitorSQLExecutionTime.ts
app/lib/other_constants.ts
+4
-1
4 additions, 1 deletion
app/lib/other_constants.ts
with
35 additions
and
26 deletions
app/lib/debug/MonitorLokiExecutionTime.ts
+
16
−
13
View file @
419cb6a5
...
...
@@ -13,26 +13,29 @@
import
{
NewLogger
}
from
"
../logger
"
import
{
getMicrosecondsTime
}
from
"
../../ProcessCpuProfiler
"
import
{
OtherConstants
}
from
"
../other_constants
"
const
theLogger
=
NewLogger
()
export
const
MonitorLokiExecutionTime
=
function
(
dumpFirstParam
=
false
)
{
return
function
(
target
:
any
,
propertyKey
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
original
=
descriptor
.
value
if
(
original
.
__proto__
.
constructor
.
name
===
"
AsyncFunction
"
)
{
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
const
that
:
any
=
this
const
now
=
getMicrosecondsTime
()
const
result
=
await
original
.
apply
(
this
,
args
)
if
(
dumpFirstParam
)
{
theLogger
.
trace
(
'
[loki][%s][%s] => %sµs
'
,
that
.
collectionName
,
propertyKey
,
(
getMicrosecondsTime
()
-
now
),
args
&&
args
[
0
])
}
else
{
theLogger
.
trace
(
'
[loki][%s][%s] => %sµs
'
,
that
.
collectionName
,
propertyKey
,
(
getMicrosecondsTime
()
-
now
))
if
(
OtherConstants
.
ENABLE_LOKI_MONITORING
)
{
const
original
=
descriptor
.
value
if
(
original
.
__proto__
.
constructor
.
name
===
"
AsyncFunction
"
)
{
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
const
that
:
any
=
this
const
now
=
getMicrosecondsTime
()
const
result
=
await
original
.
apply
(
this
,
args
)
if
(
dumpFirstParam
)
{
theLogger
.
trace
(
'
[loki][%s][%s] => %sµs
'
,
that
.
collectionName
,
propertyKey
,
(
getMicrosecondsTime
()
-
now
),
args
&&
args
[
0
])
}
else
{
theLogger
.
trace
(
'
[loki][%s][%s] => %sµs
'
,
that
.
collectionName
,
propertyKey
,
(
getMicrosecondsTime
()
-
now
))
}
return
result
}
return
result
}
else
{
throw
Error
(
"
Monitoring a Loki synchronous function is not allowed.
"
)
}
}
else
{
throw
Error
(
"
Monitoring a Loki synchronous function is not allowed.
"
)
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/lib/debug/MonitorSQLExecutionTime.ts
+
15
−
12
View file @
419cb6a5
...
...
@@ -13,24 +13,27 @@
import
{
getDurationInMicroSeconds
,
getMicrosecondsTime
}
from
"
../../ProcessCpuProfiler
"
import
{
NewLogger
}
from
"
../logger
"
import
{
OtherConstants
}
from
"
../other_constants
"
const
theLogger
=
NewLogger
()
export
const
MonitorSQLExecutionTime
=
function
()
{
return
function
(
target
:
any
,
propertyKey
:
string
,
descriptor
:
PropertyDescriptor
)
{
const
original
=
descriptor
.
value
if
(
original
.
__proto__
.
constructor
.
name
===
"
AsyncFunction
"
)
{
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
const
start
=
getMicrosecondsTime
()
const
sql
:
string
=
args
[
0
]
const
params
:
any
[]
=
args
[
1
]
const
entities
:
any
[]
=
await
original
.
apply
(
this
,
args
)
const
duration
=
getDurationInMicroSeconds
(
start
)
theLogger
.
trace
(
'
[sqlite][query] %s %s %sµs
'
,
sql
,
JSON
.
stringify
(
params
||
[]),
duration
)
return
entities
if
(
OtherConstants
.
ENABLE_SQL_MONITORING
)
{
const
original
=
descriptor
.
value
if
(
original
.
__proto__
.
constructor
.
name
===
"
AsyncFunction
"
)
{
descriptor
.
value
=
async
function
(...
args
:
any
[])
{
const
start
=
getMicrosecondsTime
()
const
sql
:
string
=
args
[
0
]
const
params
:
any
[]
=
args
[
1
]
const
entities
:
any
[]
=
await
original
.
apply
(
this
,
args
)
const
duration
=
getDurationInMicroSeconds
(
start
)
theLogger
.
trace
(
'
[sqlite][query] %s %s %sµs
'
,
sql
,
JSON
.
stringify
(
params
||
[]),
duration
)
return
entities
}
}
else
{
throw
Error
(
"
Monitoring an SQL synchronous function is not allowed.
"
)
}
}
else
{
throw
Error
(
"
Monitoring an SQL synchronous function is not allowed.
"
)
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/lib/other_constants.ts
+
4
−
1
View file @
419cb6a5
...
...
@@ -20,5 +20,8 @@ export const OtherConstants = {
SWITCHED
:
'
switched
'
,
HEAD_CHANGED
:
'
newHEAD
'
,
RESOLUTION_DONE
:
'
resolution_done
'
}
},
ENABLE_LOKI_MONITORING
:
false
,
ENABLE_SQL_MONITORING
:
false
,
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment