Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Loki
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Loki
Commits
2bbb4648
Commit
2bbb4648
authored
5 years ago
by
Marco Pracucci
Committed by
Cyril Tovena
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed orderedDeps() order stability (#721)
parent
4fccb282
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/loki/modules.go
+26
-14
26 additions, 14 deletions
pkg/loki/modules.go
pkg/loki/modules_test.go
+17
-1
17 additions, 1 deletion
pkg/loki/modules_test.go
with
43 additions
and
15 deletions
pkg/loki/modules.go
+
26
−
14
View file @
2bbb4648
...
...
@@ -238,38 +238,50 @@ func listDeps(m moduleName) []moduleName {
// orderedDeps gets a list of all dependencies ordered so that items are always after any of their dependencies.
func
orderedDeps
(
m
moduleName
)
[]
moduleName
{
deps
:=
listDeps
(
m
)
// get a unique list of dependencies and init a map to keep whether they have been added to our result
deps
:=
uniqueDeps
(
listDeps
(
m
))
added
:=
map
[
moduleName
]
bool
{}
// get a unique list of moduleNames, with a flag for whether they have been added to our result
uniq
:=
map
[
moduleName
]
bool
{}
for
_
,
dep
:=
range
deps
{
uniq
[
dep
]
=
false
}
result
:=
make
([]
moduleName
,
0
,
len
(
uniq
))
result
:=
make
([]
moduleName
,
0
,
len
(
deps
))
// keep looping through all modules until they have all been added to the result.
for
len
(
result
)
<
len
(
uniq
)
{
for
len
(
result
)
<
len
(
deps
)
{
OUTER
:
for
name
,
added
:=
range
uniq
{
if
added
{
for
_
,
name
:=
range
deps
{
if
added
[
name
]
{
continue
}
for
_
,
dep
:=
range
modules
[
name
]
.
deps
{
// stop processing this module if one of its dependencies has
// not been added to the result yet.
if
!
uniq
[
dep
]
{
if
!
added
[
dep
]
{
continue
OUTER
}
}
// if all of the module's dependencies have been added to the result slice,
// then we can safely add this module to the result slice as well.
uniq
[
name
]
=
true
added
[
name
]
=
true
result
=
append
(
result
,
name
)
}
}
return
result
}
// uniqueDeps returns the unique list of input dependencies, guaranteeing input order stability
func
uniqueDeps
(
deps
[]
moduleName
)
[]
moduleName
{
result
:=
make
([]
moduleName
,
0
,
len
(
deps
))
uniq
:=
map
[
moduleName
]
bool
{}
for
_
,
dep
:=
range
deps
{
if
!
uniq
[
dep
]
{
result
=
append
(
result
,
dep
)
uniq
[
dep
]
=
true
}
}
return
result
}
...
...
This diff is collapsed.
Click to expand it.
pkg/loki/modules_test.go
+
17
−
1
View file @
2bbb4648
...
...
@@ -2,9 +2,11 @@ package loki
import
(
"testing"
"github.com/stretchr/testify/assert"
)
func
Test
Get
Deps
(
t
*
testing
.
T
)
{
func
Test
Ordered
Deps
(
t
*
testing
.
T
)
{
for
_
,
m
:=
range
[]
moduleName
{
All
,
Distributor
,
Ingester
,
Querier
}
{
deps
:=
orderedDeps
(
m
)
seen
:=
make
(
map
[
moduleName
]
struct
{})
...
...
@@ -19,3 +21,17 @@ func TestGetDeps(t *testing.T) {
}
}
}
func
TestOrderedDepsShouldGuaranteeStabilityAcrossMultipleRuns
(
t
*
testing
.
T
)
{
initial
:=
orderedDeps
(
All
)
for
i
:=
0
;
i
<
10
;
i
++
{
assert
.
Equal
(
t
,
initial
,
orderedDeps
(
All
))
}
}
func
TestUniqueDeps
(
t
*
testing
.
T
)
{
input
:=
[]
moduleName
{
Server
,
Overrides
,
Distributor
,
Overrides
,
Server
,
Ingester
,
Server
}
expected
:=
[]
moduleName
{
Server
,
Overrides
,
Distributor
,
Ingester
}
assert
.
Equal
(
t
,
expected
,
uniqueDeps
(
input
))
}
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