Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
org-static
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
Stephen D
org-static
Commits
33fd1286
Commit
33fd1286
authored
2 years ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
metric auth
parent
3b0b395d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/config.rs
+6
-0
6 additions, 0 deletions
src/config.rs
src/main.rs
+11
-9
11 additions, 9 deletions
src/main.rs
src/metrics.rs
+11
-1
11 additions, 1 deletion
src/metrics.rs
with
28 additions
and
10 deletions
src/config.rs
+
6
−
0
View file @
33fd1286
...
...
@@ -3,6 +3,11 @@ use std::fs;
use
anyhow
::
anyhow
;
use
serde
::
Deserialize
;
#[derive(Deserialize)]
pub
struct
Metrics
{
pub
auth
:
String
,
}
#[derive(Deserialize)]
pub
struct
Logo
{
pub
path
:
String
,
...
...
@@ -18,6 +23,7 @@ pub struct Config {
pub
path
:
String
,
pub
root
:
String
,
pub
logo
:
Option
<
Logo
>
,
pub
metrics
:
Metrics
,
}
impl
Config
{
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
11
−
9
View file @
33fd1286
...
...
@@ -61,21 +61,23 @@ async fn handle_request(
#[tokio::main]
async
fn
main
()
{
let
config
=
Config
::
load
()
.unwrap
();
let
metric_auth
=
config
.metrics.auth
.clone
();
let
timer
=
BUILD_BLOG_FROM_ASSETS
.start_timer
();
let
blog
:
RenderedBlog
=
Blog
::
new
(
config
)
.unwrap
()
.try_into
()
.unwrap
();
let
blog
=
Arc
::
new
(
RwLock
::
new
(
blog
));
timer
.observe_duration
();
let
metrics_filter
=
warp
::
path!
(
"metrics"
)
.and_then
(
metrics
::
metrics_handler
);
let
metrics_path
=
warp
::
path!
(
"metrics"
)
.and
(
warp
::
any
()
.map
(
move
||
metric_auth
.clone
()))
.and
(
warp
::
query
())
.and_then
(
metrics
::
metrics_handler
);
let
blog_filter
=
warp
::
any
()
.map
(
move
||
blog
.clone
());
let
blog_path
=
warp
::
filters
::
path
::
full
()
.and
(
warp
::
any
()
.map
(
move
||
blog
.clone
()))
.and_then
(
handle_request
);
warp
::
serve
(
metrics_filter
.or
(
warp
::
filters
::
path
::
full
()
.and
(
blog_filter
.clone
())
.and_then
(
handle_request
)),
)
.run
(([
0
,
0
,
0
,
0
],
3030
))
.await
;
warp
::
serve
(
metrics_path
.or
(
blog_path
))
.run
(([
0
,
0
,
0
,
0
],
3030
))
.await
;
}
This diff is collapsed.
Click to expand it.
src/metrics.rs
+
11
−
1
View file @
33fd1286
...
...
@@ -2,6 +2,7 @@ use lazy_static::lazy_static;
use
prometheus
::{
register_counter
,
register_counter_vec
,
register_histogram
,
Counter
,
CounterVec
,
Histogram
,
};
use
serde
::
Deserialize
;
use
warp
::{
Rejection
,
Reply
};
lazy_static!
{
...
...
@@ -24,7 +25,16 @@ lazy_static! {
.unwrap
();
}
pub
async
fn
metrics_handler
()
->
Result
<
impl
Reply
,
Rejection
>
{
#[derive(Deserialize)]
pub
struct
AuthQuery
{
auth
:
String
,
}
pub
async
fn
metrics_handler
(
pass
:
String
,
query
:
AuthQuery
)
->
Result
<
impl
Reply
,
Rejection
>
{
if
query
.auth
!=
pass
{
return
Ok
(
"Go away"
.to_string
());
}
use
prometheus
::
Encoder
;
let
encoder
=
prometheus
::
TextEncoder
::
new
();
...
...
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