Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
key-storage-agent
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Code
Merge requests
2
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
key-storage-agent
Commits
a7aa86cc
Commit
a7aa86cc
authored
4 years ago
by
Gospodin Bodurov
Browse files
Options
Downloads
Plain Diff
Merge branch 'prometheus-integration' into 'master'
Prometheus integration See merge request
!62
parents
90e38c53
2a306e1c
No related branches found
No related tags found
1 merge request
!62
Prometheus integration
Pipeline
#32111
failed with stages
Stage:
Stage:
in 2 seconds
Changes
3
Pipelines
9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config/configs.go
+9
-1
9 additions, 1 deletion
config/configs.go
main.go
+7
-0
7 additions, 0 deletions
main.go
server/server.go
+59
-1
59 additions, 1 deletion
server/server.go
with
75 additions
and
2 deletions
config/configs.go
+
9
−
1
View file @
a7aa86cc
...
...
@@ -37,6 +37,9 @@ var EntitiesManagerUrl string
var
CertDir
string
var
GlobalLogLevel
string
var
PrometeusListenAddress
string
var
MetricEnvPrefix
string
func
SetConfigValues
(
configFile
,
etcdURL
string
)
{
// Set Default Values For Config Variables
...
...
@@ -141,12 +144,17 @@ func SetConfigValues(configFile, etcdURL string) {
MaxMessageSize
=
viper
.
GetInt
(
"maxMessageSize"
)
PrometeusListenAddress
=
viper
.
GetString
(
"prometeusListenAddress"
)
MetricEnvPrefix
=
viper
.
GetString
(
"metricEnvPrefix"
)
GlobalLogLevel
=
viper
.
GetString
(
"globalLogLevel"
)
CertificatePEM
=
GetCertificatePEM
()
PrivateKeyPEM
=
GetPrivateKeyPEM
()
CaCertificatePEM
=
GetCaCertificatePEM
()
VereignCaCertificatePEM
=
GetVereignCaCertificatePEM
()
VereignCaKeyPEM
=
GetVereignCaKeyPEM
()
GlobalLogLevel
=
viper
.
GetString
(
"globalLogLevel"
)
}
func
GetCertificatePEM
()
[]
byte
{
...
...
This diff is collapsed.
Click to expand it.
main.go
+
7
−
0
View file @
a7aa86cc
...
...
@@ -70,6 +70,13 @@ func main() {
}
}()
go
func
()
{
err
:=
server
.
StartPrometheusServer
()
if
err
!=
nil
{
log
.
Printf
(
"failed to start prometheus server: %v"
,
err
)
}
}()
// infinite loop
log
.
Printf
(
"Entering infinite loop"
)
select
{}
...
...
This diff is collapsed.
Click to expand it.
server/server.go
+
59
−
1
View file @
a7aa86cc
...
...
@@ -18,13 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import
(
"code.vereign.com/code/viam-apis/errors"
"crypto/tls"
"crypto/x509"
"fmt"
"net"
"net/http"
"strings"
"sync"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"code.vereign.com/code/viam-apis/errors"
"code.vereign.com/code/viam-apis/log"
...
...
@@ -41,6 +46,9 @@ import (
"google.golang.org/grpc/metadata"
)
var
mutex
sync
.
RWMutex
var
summaries
=
make
(
map
[
string
]
prometheus
.
Summary
)
// private type for Context keys
type
contextKey
int
...
...
@@ -112,6 +120,40 @@ func unaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServ
return
res
,
err
}
func
createQueryTime
(
funcName
string
)
prometheus
.
Summary
{
if
config
.
PrometeusListenAddress
!=
""
{
endPointName
:=
strings
.
Replace
(
funcName
,
"/"
,
"_"
,
-
1
)
endPointName
=
strings
.
Replace
(
endPointName
,
"."
,
"_"
,
-
1
)
metricName
:=
endPointName
+
"_grpc_request_duration_seconds"
if
config
.
MetricEnvPrefix
!=
""
{
metricName
=
config
.
MetricEnvPrefix
+
"_"
+
metricName
}
mutex
.
Lock
()
defer
mutex
.
Unlock
()
queryTime
,
ok
:=
summaries
[
metricName
]
if
ok
==
false
{
queryTime
=
prometheus
.
NewSummary
(
prometheus
.
SummaryOpts
{
Name
:
metricName
,
Help
:
"grpc request duration seconds of /"
+
funcName
+
" for "
+
config
.
MetricEnvPrefix
+
" env"
,
})
// init metrics
prometheus
.
MustRegister
(
queryTime
)
summaries
[
metricName
]
=
queryTime
}
return
queryTime
}
return
nil
}
func
StartGRPCServer
(
address
string
,
certPEM
,
privateKeyPEM
,
caCertPEM
,
vereignCertPEM
,
vereignPrivateKeyPEM
[]
byte
,
dataStorageAddress
string
,
maxMessageSize
int
)
error
{
pkgCertPEM
=
certPEM
pkgKeyPEM
=
privateKeyPEM
...
...
@@ -217,3 +259,19 @@ func StartRESTServer(address, grpcAddress string, certPEM []byte) error {
return
nil
}
func
StartPrometheusServer
()
error
{
if
config
.
PrometeusListenAddress
!=
""
{
// start prometheus
promHandler
:=
http
.
NewServeMux
()
promHandler
.
Handle
(
"/metrics"
,
promhttp
.
Handler
())
log
.
Println
(
"Starting prometheus..."
)
err
:=
http
.
ListenAndServe
(
config
.
PrometeusListenAddress
,
promHandler
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
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