Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Q
query-service
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
GraphPolaris
Microservices
query-service
Merge requests
!20
feat: adds stats check and update
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
feat: adds stats check and update
feat/checkAlartmStats&UpdateStatus
into
main
Overview
1
Commits
1
Pipelines
1
Changes
1
Closed
Marcos Pieras
requested to merge
feat/checkAlartmStats&UpdateStatus
into
main
2 months ago
Overview
1
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
fb16fd6a
1 commit,
2 months ago
1 file
+
141
−
80
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Conflict: This file was modified in both the source and target branches. Ask someone with write access to resolve it.
src/readers/insightProcessor.ts
+
141
−
80
Options
import
{
RabbitMqBroker
,
populateTemplate
}
from
"
ts-common
"
;
import
{
rabbitMq
,
ums
}
from
"
../variables
"
;
import
{
log
}
from
"
../logger
"
;
import
type
{
InsightModel
}
from
"
ts-common/src/model/webSocket/insight
"
;
import
{
VariableNode
}
from
'
../utils/lexical
'
;
import
{
createHeadlessEditor
}
from
'
@lexical/headless
'
;
import
{
$generateHtmlFromNodes
}
from
'
@lexical/html
'
;
import
{
JSDOM
}
from
'
jsdom
'
;
import
{
Query2BackendQuery
}
from
"
../utils/reactflow/query2backend
"
;
import
{
query2Cypher
}
from
"
../utils/cypher/converter
"
;
import
{
queryService
}
from
'
./queryService
'
;
const
dom
=
new
JSDOM
();
function
setUpDom
()
{
const
_window
=
global
.
window
;
const
_document
=
global
.
document
;
const
_documentFragment
=
global
.
DocumentFragment
;
const
_navigator
=
global
.
navigator
;
// @ts-ignore
global
.
window
=
dom
.
window
;
global
.
document
=
dom
.
window
.
document
;
global
.
DocumentFragment
=
dom
.
window
.
DocumentFragment
;
global
.
navigator
=
dom
.
window
.
navigator
;
return
()
=>
{
// @ts-ignore
global
.
window
=
_window
;
global
.
document
=
_document
;
global
.
DocumentFragment
=
_documentFragment
;
global
.
navigator
=
_navigator
;
};
}
export
const
insightProcessor
=
async
()
=>
{
log
.
info
(
'
Starting insight processor
'
);
const
insightProcessorConsumer
=
await
new
RabbitMqBroker
(
rabbitMq
,
'
insight-processor
'
,
`insight-processor`
,
`insight-processor`
).
connect
();
log
.
info
(
'
Connected to RabbitMQ ST!
'
);
await
insightProcessorConsumer
.
startConsuming
<
InsightModel
>
(
"
query-service
"
,
async
(
message
,
headers
)
=>
{
log
.
info
(
'
Received insight to be processed
'
,
message
);
const
editor
=
createHeadlessEditor
({
nodes
:
[
VariableNode
],
onError
:
(
error
)
=>
{
log
.
error
(
error
)
},
});
editor
.
update
(()
=>
{
const
state
=
editor
.
parseEditorState
(
JSON
.
parse
(
message
.
template
));
editor
.
setEditorState
(
state
);
});
if
(
message
.
userId
==
null
)
return
;
const
ss
=
await
ums
.
getUserSaveState
(
message
.
userId
,
message
.
saveStateId
);
const
visualizations
=
ss
.
visualizations
.
openVisualizationArray
;
const
visualQuery
=
ss
.
queries
[
0
].
graph
;
const
queryBuilderSettings
=
ss
.
queries
[
0
].
settings
;
const
convertedQuery
=
Query2BackendQuery
(
ss
.
id
,
visualQuery
,
queryBuilderSettings
,
[]);
const
query
=
query2Cypher
(
convertedQuery
);
if
(
query
==
null
)
return
;
const
result
=
await
queryService
(
ss
.
dbConnections
[
0
],
query
);
editor
.
read
(
async
()
=>
{
const
cleanUpDom
=
setUpDom
();
let
html
=
$generateHtmlFromNodes
(
editor
);
cleanUpDom
();
html
=
await
populateTemplate
(
html
,
result
,
visualizations
);
console
.
log
(
'
HTML:
'
,
html
);
});
});
}
import
{
RabbitMqBroker
,
populateTemplate
}
from
"
ts-common
"
;
import
{
rabbitMq
,
ums
}
from
"
../variables
"
;
import
{
log
}
from
"
../logger
"
;
import
type
{
InsightModel
}
from
"
ts-common/src/model/webSocket/insight
"
;
import
{
VariableNode
}
from
"
../utils/lexical
"
;
import
{
createHeadlessEditor
}
from
"
@lexical/headless
"
;
import
{
$generateHtmlFromNodes
}
from
"
@lexical/html
"
;
import
{
JSDOM
}
from
"
jsdom
"
;
import
{
Query2BackendQuery
}
from
"
../utils/reactflow/query2backend
"
;
import
{
query2Cypher
}
from
"
../utils/cypher/converter
"
;
import
{
queryService
}
from
"
./queryService
"
;
const
dom
=
new
JSDOM
();
function
setUpDom
()
{
const
_window
=
global
.
window
;
const
_document
=
global
.
document
;
const
_documentFragment
=
global
.
DocumentFragment
;
const
_navigator
=
global
.
navigator
;
// @ts-ignore
global
.
window
=
dom
.
window
;
global
.
document
=
dom
.
window
.
document
;
global
.
DocumentFragment
=
dom
.
window
.
DocumentFragment
;
global
.
navigator
=
dom
.
window
.
navigator
;
return
()
=>
{
// @ts-ignore
global
.
window
=
_window
;
global
.
document
=
_document
;
global
.
DocumentFragment
=
_documentFragment
;
global
.
navigator
=
_navigator
;
};
}
/*
function processAlarmStats(alarmStat: InsightModel, resultQuery: GraphQueryResultMetaFromBackend) {
const ssInsightNode = alarmStat.statsCheck.node;
const ssInsightStatistic = alarmStat.statsCheck.statistic;
const ssInsightCondition = alarmStat.statsCheck.condition;
const ssInsightValue = alarmStat.statsCheck.value;
if (resultQuery.metaData.nodes.labels.includes(ssInsightNode)) {
const nodeCount = resultQuery.metaData.nodes.count;
let conditionMet = false;
switch (ssInsightCondition) {
case "Greater than":
conditionMet = nodeCount > ssInsightValue;
break;
case "Equal than":
conditionMet = nodeCount === ssInsightValue;
break;
case "Smaller than":
conditionMet = nodeCount < ssInsightValue;
break;
default:
log.error(`Unsupported condition: ${ssInsightCondition}`);
throw new Error(`Unsupported condition: ${ssInsightCondition}`);
}
if (conditionMet) {
log.info("Condition met ");
return true;
} else {
log.info("Condition not met");
return false;
}
}
return false;
}
*/
export
const
insightProcessor
=
async
()
=>
{
log
.
info
(
"
Starting insight processor
"
);
const
insightProcessorConsumer
=
await
new
RabbitMqBroker
(
rabbitMq
,
"
insight-processor
"
,
`insight-processor`
,
`insight-processor`
).
connect
();
log
.
info
(
"
Connected to RabbitMQ ST!
"
);
await
insightProcessorConsumer
.
startConsuming
<
InsightModel
>
(
"
query-service
"
,
async
(
message
,
headers
)
=>
{
log
.
info
(
"
Received insight to be processed
"
,
message
);
const
editor
=
createHeadlessEditor
({
nodes
:
[
VariableNode
],
onError
:
(
error
)
=>
{
log
.
error
(
error
);
},
});
editor
.
update
(()
=>
{
const
state
=
editor
.
parseEditorState
(
JSON
.
parse
(
message
.
template
));
editor
.
setEditorState
(
state
);
});
if
(
message
.
userId
==
null
)
return
;
const
ss
=
await
ums
.
getUserSaveState
(
message
.
userId
,
message
.
saveStateId
);
const
insights
=
await
ums
.
getInsights
(
message
.
userId
,
message
.
saveStateId
);
const
visualizations
=
ss
.
visualizations
.
openVisualizationArray
;
const
visualQuery
=
ss
.
queries
[
0
].
graph
;
const
queryBuilderSettings
=
ss
.
queries
[
0
].
settings
;
const
convertedQuery
=
Query2BackendQuery
(
ss
.
id
,
visualQuery
,
queryBuilderSettings
,
[]);
const
query
=
query2Cypher
(
convertedQuery
);
if
(
query
==
null
)
return
;
const
result
=
await
queryService
(
ss
.
dbConnections
[
0
],
query
);
if
(
insights
==
null
)
return
;
const
alerts
=
insights
.
filter
((
entry
)
=>
entry
.
type
===
"
alert
"
);
const
reports
=
insights
.
filter
((
entry
)
=>
entry
.
type
===
"
report
"
);
// check if the alarm is triggered
await
Promise
.
all
(
alerts
.
map
(
async
(
singleAlert
)
=>
{
log
.
info
(
"
alerts!
"
,
singleAlert
);
//const statusResult = processAlarmStats(singleAlert, result);
const
singleAlertModified
=
{
...
singleAlert
,
status
:
true
,
//statusResult,
};
log
.
info
(
"
singleAlert!
"
,
singleAlertModified
);
// TODO! change updatedField in insight ?
await
ums
.
updateInsight
(
headers
.
message
.
sessionData
.
userID
,
String
(
singleAlert
.
id
),
singleAlertModified
);
})
);
editor
.
read
(
async
()
=>
{
const
cleanUpDom
=
setUpDom
();
let
html
=
$generateHtmlFromNodes
(
editor
);
cleanUpDom
();
html
=
await
populateTemplate
(
html
,
result
,
visualizations
);
console
.
log
(
"
HTML:
"
,
html
);
});
});
};
Loading