Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
keystore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
id
keystore
Commits
6e243559
Commit
6e243559
authored
5 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add specific instrumentation for Keystore operations
parent
0a172661
No related branches found
No related tags found
1 merge request
!2
Add specific instrumentation for Keystore operations
Pipeline
#5429
passed
5 years ago
Stage: build_pkgsrc
Stage: build_pkg
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/instrumentation.go
+26
-0
26 additions, 0 deletions
server/instrumentation.go
server/keystore.go
+3
-0
3 additions, 0 deletions
server/keystore.go
server/server.go
+7
-0
7 additions, 0 deletions
server/server.go
with
36 additions
and
0 deletions
server/instrumentation.go
0 → 100644
+
26
−
0
View file @
6e243559
package
server
import
"github.com/prometheus/client_golang/prometheus"
var
(
totalKeysInMemory
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"keystored_keys_total"
,
Help
:
"Total number of unlocked keys in-memory."
,
})
requestsCounter
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"keystored_requests_total"
,
Help
:
"Counter of requests by method and status."
,
},
[]
string
{
"method"
,
"status"
})
decryptedKeysCounter
=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"keystored_decrypted_keys_total"
,
Help
:
"Counter of decrypted keys."
,
})
unlockedKeysServedCounter
=
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"keystored_unlocked_keys_served_total"
,
Help
:
"Counter of unlocked keys served."
,
})
)
func
(
s
*
KeyStore
)
updateKeyspaceSize
()
{
totalKeysInMemory
.
Set
(
float64
(
len
(
s
.
userKeys
)))
}
This diff is collapsed.
Click to expand it.
server/keystore.go
+
3
−
0
View file @
6e243559
...
...
@@ -127,6 +127,7 @@ func (s *KeyStore) expire(t time.Time) {
delete
(
s
.
userKeys
,
u
)
}
}
s
.
updateKeyspaceSize
()
s
.
mx
.
Unlock
()
}
...
...
@@ -173,6 +174,7 @@ func (s *KeyStore) Open(ctx context.Context, username, password string, ttlSecon
pkey
:
pem
,
expiry
:
time
.
Now
()
.
Add
(
time
.
Duration
(
ttlSeconds
)
*
time
.
Second
),
}
s
.
updateKeyspaceSize
()
s
.
mx
.
Unlock
()
return
nil
}
...
...
@@ -210,6 +212,7 @@ func (s *KeyStore) Close(username string) bool {
if
ok
{
wipeBytes
(
k
.
pkey
)
delete
(
s
.
userKeys
,
username
)
s
.
updateKeyspaceSize
()
}
return
ok
}
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
7
−
0
View file @
6e243559
...
...
@@ -27,11 +27,14 @@ func (s *keyStoreServer) handleOpen(w http.ResponseWriter, r *http.Request) {
}
else
if
err
!=
nil
{
log
.
Printf
(
"Open(%s): error: %v"
,
req
.
Username
,
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
requestsCounter
.
WithLabelValues
(
"Open"
,
"error"
)
.
Inc
()
return
}
else
{
log
.
Printf
(
"Open(%s): decrypted key, ttl=%d"
,
req
.
Username
,
req
.
TTL
)
decryptedKeysCounter
.
Inc
()
}
requestsCounter
.
WithLabelValues
(
"Open"
,
"ok"
)
.
Inc
()
serverutil
.
EncodeJSONResponse
(
w
,
&
emptyResponse
)
}
...
...
@@ -54,13 +57,16 @@ func (s *keyStoreServer) handleGet(w http.ResponseWriter, r *http.Request) {
log
.
Printf
(
"Get(%s): error: %v"
,
req
.
Username
,
err
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
}
requestsCounter
.
WithLabelValues
(
"Get"
,
"error"
)
.
Inc
()
return
}
else
{
resp
.
HasKey
=
true
resp
.
Key
=
key
log
.
Printf
(
"Get(%s): fetched key"
,
req
.
Username
)
unlockedKeysServedCounter
.
Inc
()
}
requestsCounter
.
WithLabelValues
(
"Get"
,
"ok"
)
.
Inc
()
serverutil
.
EncodeJSONResponse
(
w
,
&
resp
)
}
...
...
@@ -74,6 +80,7 @@ func (s *keyStoreServer) handleClose(w http.ResponseWriter, r *http.Request) {
log
.
Printf
(
"Close(%s): discarded key"
,
req
.
Username
)
}
requestsCounter
.
WithLabelValues
(
"Close"
,
"ok"
)
.
Inc
()
serverutil
.
EncodeJSONResponse
(
w
,
&
emptyResponse
)
}
...
...
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