Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
tci-gateway-module
Grpc
Commits
a5b482a8
Commit
a5b482a8
authored
9 years ago
by
murgatroid99
Browse files
Options
Downloads
Patches
Plain Diff
Updated health check service with new changes
parent
2be6ac0d
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
src/node/health_check/health.js
+12
-3
12 additions, 3 deletions
src/node/health_check/health.js
src/node/health_check/health.proto
+2
-1
2 additions, 1 deletion
src/node/health_check/health.proto
src/node/test/health_test.js
+29
-17
29 additions, 17 deletions
src/node/test/health_test.js
with
43 additions
and
21 deletions
src/node/health_check/health.js
+
12
−
3
View file @
a5b482a8
...
@@ -45,13 +45,22 @@ function HealthImplementation(statusMap) {
...
@@ -45,13 +45,22 @@ function HealthImplementation(statusMap) {
this
.
statusMap
=
_
.
clone
(
statusMap
);
this
.
statusMap
=
_
.
clone
(
statusMap
);
}
}
HealthImplementation
.
prototype
.
setStatus
=
function
(
service
,
status
)
{
HealthImplementation
.
prototype
.
setStatus
=
function
(
host
,
service
,
status
)
{
this
.
statusMap
[
service
]
=
status
;
if
(
!
this
.
statusMap
[
host
])
{
this
.
statusMap
[
host
]
=
{};
}
this
.
statusMap
[
host
][
service
]
=
status
;
};
};
HealthImplementation
.
prototype
.
check
=
function
(
call
,
callback
){
HealthImplementation
.
prototype
.
check
=
function
(
call
,
callback
){
var
host
=
call
.
request
.
host
;
var
service
=
call
.
request
.
service
;
var
service
=
call
.
request
.
service
;
callback
(
null
,
{
status
:
_
.
get
(
this
.
statusMap
,
service
,
'
UNKNOWN
'
)});
var
status
=
_
.
get
(
this
.
statusMap
,
[
host
,
service
],
null
);
if
(
status
===
null
)
{
callback
({
code
:
grpc
.
status
.
NOT_FOUND
});
}
else
{
callback
(
null
,
{
status
:
status
});
}
};
};
module
.
exports
=
{
module
.
exports
=
{
...
...
This diff is collapsed.
Click to expand it.
src/node/health_check/health.proto
+
2
−
1
View file @
a5b482a8
...
@@ -32,7 +32,8 @@ syntax = "proto3";
...
@@ -32,7 +32,8 @@ syntax = "proto3";
package
grpc
.
health.v1alpha
;
package
grpc
.
health.v1alpha
;
message
HealthCheckRequest
{
message
HealthCheckRequest
{
string
service
=
1
;
string
host
=
1
;
string
service
=
2
;
}
}
message
HealthCheckResponse
{
message
HealthCheckResponse
{
...
...
This diff is collapsed.
Click to expand it.
src/node/test/health_test.js
+
29
−
17
View file @
a5b482a8
...
@@ -40,13 +40,18 @@ var health = require('../health_check/health.js');
...
@@ -40,13 +40,18 @@ var health = require('../health_check/health.js');
var
grpc
=
require
(
'
../
'
);
var
grpc
=
require
(
'
../
'
);
describe
(
'
Health Checking
'
,
function
()
{
describe
(
'
Health Checking
'
,
function
()
{
var
statusMap
=
{
''
:
{
''
:
'
SERVING
'
,
'
grpc.test.TestService
'
:
'
NOT_SERVING
'
,
},
virtual_host
:
{
'
grpc.test.TestService
'
:
'
SERVING
'
}
};
var
HealthServer
=
grpc
.
buildServer
([
health
.
service
]);
var
HealthServer
=
grpc
.
buildServer
([
health
.
service
]);
var
healthServer
=
new
HealthServer
({
var
healthServer
=
new
HealthServer
({
'
grpc.health.v1alpha.Health
'
:
new
health
.
Implementation
({
'
grpc.health.v1alpha.Health
'
:
new
health
.
Implementation
(
statusMap
)
''
:
'
SERVING
'
,
'
grpc.health.v1alpha.Health
'
:
'
SERVING
'
,
'
not.serving.Service
'
:
'
NOT_SERVING
'
})
});
});
var
healthClient
;
var
healthClient
;
before
(
function
()
{
before
(
function
()
{
...
@@ -57,34 +62,41 @@ describe('Health Checking', function() {
...
@@ -57,34 +62,41 @@ describe('Health Checking', function() {
after
(
function
()
{
after
(
function
()
{
healthServer
.
shutdown
();
healthServer
.
shutdown
();
});
});
it
(
'
should
respond with SERVING with no service specified
'
,
function
(
done
)
{
it
(
'
should
say an enabled service is SERVING
'
,
function
(
done
)
{
healthClient
.
check
({},
function
(
err
,
response
)
{
healthClient
.
check
({
service
:
''
},
function
(
err
,
response
)
{
assert
.
ifError
(
err
);
assert
.
ifError
(
err
);
assert
.
strictEqual
(
response
.
status
,
'
SERVING
'
);
assert
.
strictEqual
(
response
.
status
,
'
SERVING
'
);
done
();
done
();
});
});
});
});
it
(
'
should
respond that the health check
service is SERVING
'
,
function
(
done
)
{
it
(
'
should
say that a disabled
service is
NOT_
SERVING
'
,
function
(
done
)
{
healthClient
.
check
({
service
:
'
grpc.
health.v1alpha.Health
'
},
healthClient
.
check
({
service
:
'
grpc.
test.TestService
'
},
function
(
err
,
response
)
{
function
(
err
,
response
)
{
assert
.
ifError
(
err
);
assert
.
ifError
(
err
);
assert
.
strictEqual
(
response
.
status
,
'
SERVING
'
);
assert
.
strictEqual
(
response
.
status
,
'
NOT_
SERVING
'
);
done
();
done
();
});
});
});
});
it
(
'
should
respond
that a
disabled service is NOT_
SERVING
'
,
function
(
done
)
{
it
(
'
should
say
that a
service on another host is
SERVING
'
,
function
(
done
)
{
healthClient
.
check
({
service
:
'
not.serving.
Service
'
},
healthClient
.
check
({
host
:
'
virtual_host
'
,
service
:
'
grpc.test.Test
Service
'
},
function
(
err
,
response
)
{
function
(
err
,
response
)
{
assert
.
ifError
(
err
);
assert
.
ifError
(
err
);
assert
.
strictEqual
(
response
.
status
,
'
NOT_
SERVING
'
);
assert
.
strictEqual
(
response
.
status
,
'
SERVING
'
);
done
();
done
();
});
});
});
});
it
(
'
should respond with UNKNOWN for an unknown service
'
,
function
(
done
)
{
it
(
'
should get NOT_FOUND if the service is not registered
'
,
function
(
done
)
{
healthClient
.
check
({
service
:
'
unknown.service.Name
'
},
healthClient
.
check
({
service
:
'
not_registered
'
},
function
(
err
,
response
)
{
assert
(
err
);
assert
.
strictEqual
(
err
.
code
,
grpc
.
status
.
NOT_FOUND
);
done
();
});
});
it
(
'
should get NOT_FOUND if the host is not registered
'
,
function
(
done
)
{
healthClient
.
check
({
host
:
'
wrong_host
'
,
service
:
'
grpc.test.TestService
'
},
function
(
err
,
response
)
{
function
(
err
,
response
)
{
assert
.
ifError
(
err
);
assert
(
err
);
assert
.
strictEqual
(
response
.
status
,
'
UNKNOWN
'
);
assert
.
strictEqual
(
err
.
code
,
grpc
.
status
.
NOT_FOUND
);
done
();
done
();
});
});
});
});
...
...
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