Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Pupák
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
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KSZK
Open Source
Pupák
Commits
14d024e7
Verified
Commit
14d024e7
authored
May 31, 2020
by
Robotka István Adrián
Browse files
Options
Downloads
Patches
Plain Diff
commenting
parent
3964f7d6
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!6
add snippets functionality
Pipeline
#4207
passed with warnings
May 31, 2020
Stage: Get dependencies
Stage: Static Analysis
Stage: Docker build
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
build.py
+13
-10
13 additions, 10 deletions
build.py
config.py
+0
-1
0 additions, 1 deletion
config.py
customlog.py
+1
-0
1 addition, 0 deletions
customlog.py
pupak.py
+4
-4
4 additions, 4 deletions
pupak.py
with
18 additions
and
15 deletions
build.py
+
13
−
10
View file @
14d024e7
...
...
@@ -13,7 +13,6 @@ class ConfigBuilder:
"""
Fill YAML-jinja2 templates, prepare the final data-model
"""
def
__init__
(
self
,
cfg
:
Config
):
"""
Instantiate ConfigBuilder
"""
self
.
logger
=
logging
.
getLogger
(
APP_LOG_TAG
)
self
.
config
=
cfg
...
...
@@ -23,17 +22,21 @@ class ConfigBuilder:
for
job
in
service
[
'
scraping
'
]:
self
.
logger
.
debug
(
"
Templating:
"
+
service
[
'
service_name
'
]
+
'
->
'
+
job
[
'
template
'
])
self
.
load_template
(
job
)
template
=
self
.
substitute_template_field
(
job
,
service
)
# store generated prometheus job config
job
[
'
output_yaml
'
]
=
yaml
.
safe_load
(
template
)
def
load_template
(
self
,
job
):
"""
Substitute
'
template
'
field with its content
"""
template_identifier
=
TEMPLATE_PREFIX
+
job
[
'
template
'
]
job
[
'
template
'
]
=
self
.
config
.
templates
[
template_identifier
]
def
substitute_template_field
(
self
,
job
,
service
):
"""
Fill template field with data
"""
env
=
jinja2
.
Environment
(
undefined
=
jinja2
.
DebugUndefined
)
template
=
env
.
from_string
(
job
[
'
template
'
])
data
=
service
.
copy
()
data
[
'
targets
'
]
=
job
[
'
targets
'
]
data
[
'
snippet
'
]
=
collect_snippets
(
self
.
config
.
templates
)
output
=
template
.
render
(
data
)
# store generated prometheus job config
job
[
'
output_yaml
'
]
=
yaml
.
safe_load
(
output
)
def
load_template
(
self
,
job
):
template_identifier
=
TEMPLATE_PREFIX
+
job
[
'
template
'
]
job
[
'
template
'
]
=
self
.
config
.
templates
[
template_identifier
]
return
template
.
render
(
data
)
This diff is collapsed.
Click to expand it.
config.py
+
0
−
1
View file @
14d024e7
...
...
@@ -14,7 +14,6 @@ class Config:
templates
=
{}
def
__init__
(
self
,
path
:
Path
):
"""
Read service YAML files and preload templates
"""
self
.
logger
=
logging
.
getLogger
(
APP_LOG_TAG
)
# YAML files in tha data directory recursively
base_path_len
=
len
(
str
(
path
.
absolute
()))
+
1
...
...
This diff is collapsed.
Click to expand it.
customlog.py
+
1
−
0
View file @
14d024e7
...
...
@@ -5,6 +5,7 @@ from constants import APP_LOG_TAG
def
setup_logging
():
"""
Setup custom log format
"""
# create logger with 'spam_application'
logger
=
logging
.
getLogger
(
APP_LOG_TAG
)
logger
.
setLevel
(
logging
.
DEBUG
)
...
...
This diff is collapsed.
Click to expand it.
pupak.py
+
4
−
4
View file @
14d024e7
...
...
@@ -19,21 +19,21 @@ if __name__ == "__main__":
if
len
(
sys
.
argv
)
<
1
+
1
:
logger
.
error
(
"
Not enough CLI args.
"
)
logger
.
error
(
"
Usage: data_folder
"
)
exit
(
1
)
sys
.
exit
(
1
)
data_folder
=
Path
(
sys
.
argv
[
1
])
# Read service YAML files and preload templates
raw
=
Config
(
data_folder
)
config
=
Config
(
data_folder
)
# Fill YAML-jinja2 templates,
# prepare the final data-model
builder
=
ConfigBuilder
(
raw
)
builder
=
ConfigBuilder
(
config
)
builder
.
build
()
# print("Data scheme validation:")
# cfg.validate()
# print("Data scheme is VALID.")
generator
=
Generator
(
data_folder
,
builder
.
config
)
generator
=
Generator
(
data_folder
,
config
)
generator
.
ignite
()
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