Skip to content

Commit

Permalink
Apply all linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Apr 11, 2022
1 parent 18989ae commit 0c8a0c9
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 86 deletions.
133 changes: 74 additions & 59 deletions assets/js/components/ChecksResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const sortHosts = (hosts = []) => {
const getResultIcon = (checks_execution, result) => {
switch (checks_execution) {
case 'requested':
return <EOS_SCHEDULE className="fill-gray-500" />;
return <EOS_SCHEDULE className="fill-gray-500" />;
case 'running':
return <Spinner></Spinner>;
return <Spinner></Spinner>;
}

switch (result) {
Expand Down Expand Up @@ -99,68 +99,83 @@ const ChecksResults = () => {

return (
<div>
{sortHosts(cluster?.hosts_executions.slice()).map(({cluster_id, host_id, reachable, msg}) => (
<div key="c" className="flex flex-col">
<div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div className="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
<div className="bg-white px-4 py-5 border-b border-gray-200 sm:px-6">
<h3 className="text-lg leading-6 font-medium text-gray-900">
{hostname(host_id)}
</h3>
{reachable == false && (
<div class="bg-yellow-200 border-yellow-600 text-yellow-600 border-l-4 p-4" role="alert">
<p>{msg}</p>
</div>
)}
</div>
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
ID
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Description
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
{sortHosts(cluster?.hosts_executions.slice()).map(
({ cluster_id, host_id, reachable, msg }) => (
<div key="c" className="flex flex-col">
<div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div className="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
<div className="bg-white px-4 py-5 border-b border-gray-200 sm:px-6">
<h3 className="text-lg leading-6 font-medium text-gray-900">
{hostname(host_id)}
</h3>
{reachable == false && (
<div
class="bg-yellow-200 border-yellow-600 text-yellow-600 border-l-4 p-4"
role="alert"
>
Result
</th>
</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{sortChecksResults(cluster?.checks_results.slice())
.filter((check_result) => check_result.host_id == host_id)
.filter((check_result) => check_result.result != 'skipped') // Filter "skipped" results by now
.map((checkResult) => (
<tr key={checkResult.check_id} className="animate-fade">
<td className="px-6 py-4 whitespace-nowrap">
{checkResult.check_id}
</td>
<td className="px-6 py-4 whitespace-nowrap">
{description(checkResult.check_id)}
</td>
<td className="px-6 py-4 whitespace-nowrap content-center">
{getResultIcon(cluster.checks_execution, checkResult.result)}
</td>
<p>{msg}</p>
</div>
)}
</div>
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
ID
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Description
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Result
</th>
</tr>
))}
</tbody>
</table>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{sortChecksResults(cluster?.checks_results.slice())
.filter(
(check_result) => check_result.host_id == host_id
)
.filter(
(check_result) => check_result.result != 'skipped'
) // Filter "skipped" results by now
.map((checkResult) => (
<tr
key={checkResult.check_id}
className="animate-fade"
>
<td className="px-6 py-4 whitespace-nowrap">
{checkResult.check_id}
</td>
<td className="px-6 py-4 whitespace-nowrap">
{description(checkResult.check_id)}
</td>
<td className="px-6 py-4 whitespace-nowrap content-center">
{getResultIcon(
cluster.checks_execution,
checkResult.result
)}
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
))}
)
)}
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/trento/application/integration/checks/checks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ defmodule Trento.Integration.Checks do
%{
host_id: host_id,
reachable: reachable,
msg: msg,
msg: msg,
checks_results: Enum.map(results, &Map.from_struct/1)
}
end)
Expand Down
7 changes: 5 additions & 2 deletions lib/trento/application/projectors/check_result_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ defmodule Trento.CheckResultProjector do
)
end)
|> List.flatten()
|> Enum.reduce(multi, fn %{changes: %{cluster_id: cluster_id, host_id: host_id}} = changeset,
|> Enum.reduce(multi, fn %{changes: %{cluster_id: cluster_id, host_id: host_id}} =
changeset,
acc ->
Ecto.Multi.insert(acc, "#{cluster_id}_#{host_id}", changeset)
end)
Expand Down Expand Up @@ -157,7 +158,9 @@ defmodule Trento.CheckResultProjector do
TrentoWeb.Endpoint.broadcast("monitoring:clusters", "checks_results_updated", %{
cluster_id: cluster_id,
host_id: host_id,
hosts_executions: [%{cluster_id: cluster_id, host_id: host_id, reachable: reachable, msg: msg}],
hosts_executions: [
%{cluster_id: cluster_id, host_id: host_id, reachable: reachable, msg: msg}
],
checks_results:
Enum.map(checks_results, fn %{check_id: check_id, result: result} ->
%{host_id: host_id, check_id: check_id, result: result}
Expand Down
60 changes: 36 additions & 24 deletions lib/trento/domain/cluster/cluster.ex
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,10 @@ defmodule Trento.Domain.Cluster do
%HostExecution{
host_id: host_id,
reachable: true,
checks_results: Enum.map(selected_checks, fn check_id ->
%CheckResult{check_id: check_id, result: :unknown}
end)
checks_results:
Enum.map(selected_checks, fn check_id ->
%CheckResult{check_id: check_id, result: :unknown}
end)
}
)
end)
Expand Down Expand Up @@ -330,19 +331,23 @@ defmodule Trento.Domain.Cluster do

def apply(
%Cluster{hosts_executions: hosts_executions} = cluster,
%HostChecksExecutionCompleted{host_id: host_id, reachable: reachable, msg: msg, checks_results: checks_results}
)
when reachable == true do
%Cluster{
cluster
| hosts_executions: Map.put(hosts_executions, host_id,
%HostExecution{
%HostChecksExecutionCompleted{
host_id: host_id,
reachable: reachable,
msg: msg,
checks_results: checks_results
}
)
when reachable == true do
%Cluster{
cluster
| hosts_executions:
Map.put(hosts_executions, host_id, %HostExecution{
host_id: host_id,
reachable: reachable,
msg: msg,
checks_results: checks_results
})
}
end

Expand All @@ -353,14 +358,15 @@ defmodule Trento.Domain.Cluster do
when reachable == false do
%Cluster{
cluster
| hosts_executions: Map.update(hosts_executions, host_id, %HostExecution{}, fn host ->
%HostExecution{
host_id: host_id,
reachable: reachable,
msg: msg,
checks_results: host.checks_results
}
end)
| hosts_executions:
Map.update(hosts_executions, host_id, %HostExecution{}, fn host ->
%HostExecution{
host_id: host_id,
reachable: reachable,
msg: msg,
checks_results: host.checks_results
}
end)
}
end

Expand Down Expand Up @@ -465,9 +471,12 @@ defmodule Trento.Domain.Cluster do
end

defp handle_hosts_execution_data(
%{host_id: host_id, reachable: reachable, msg: msg}, multi, cluster_id, hosts_executions)
when reachable == false do

%{host_id: host_id, reachable: reachable, msg: msg},
multi,
cluster_id,
hosts_executions
)
when reachable == false do
multi
|> Multi.execute(fn _ ->
%HostChecksExecutionCompleted{
Expand All @@ -481,9 +490,12 @@ defmodule Trento.Domain.Cluster do
end

defp handle_hosts_execution_data(
%{host_id: host_id, reachable: reachable, msg: msg, checks_results: results}, multi, cluster_id, _hosts_executions)
when reachable == true do

%{host_id: host_id, reachable: reachable, msg: msg, checks_results: results},
multi,
cluster_id,
_hosts_executions
)
when reachable == true do
multi
|> Multi.execute(fn _ ->
%HostChecksExecutionCompleted{
Expand Down

0 comments on commit 0c8a0c9

Please sign in to comment.