Skip to content

Commit 3149bf8

Browse files
committed
feat: add more operationnal logging
add more meaningful data at info level add more debug logs
1 parent 2bb6323 commit 3149bf8

File tree

5 files changed

+57
-36
lines changed

5 files changed

+57
-36
lines changed

internal/mirroring/get.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
// fetchAll retrieves all projects and groups from the GitLab instance
1414
// that match the filters and stores them in the instance cache.
1515
func (g *GitlabInstance) fetchAll(projectFilters map[string]struct{}, groupFilters map[string]struct{}, mirrorMapping *utils.MirrorMapping) error {
16+
zap.L().Info("Fetching all projects and groups from GitLab instance", zap.String("role", g.Role), zap.String(INSTANCE_SIZE, g.InstanceSize), zap.Int("projects", len(projectFilters)), zap.Int("groups", len(groupFilters)))
1617
wg := sync.WaitGroup{}
1718
errCh := make(chan error, 2)
1819
wg.Add(2)

internal/mirroring/get_group.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
//
1616
// The function is run in a goroutine for each group, and a wait group is used to wait for all goroutines to finish.
1717
func (g *GitlabInstance) fetchAndProcessGroups(groupFilters *map[string]struct{}, mirrorMapping *utils.MirrorMapping) error {
18+
zap.L().Debug("Fetching and processing groups from GitLab instance", zap.String(ROLE, g.Role), zap.Int("groups", len(*groupFilters)))
1819
if !g.isBig() {
1920
return g.fetchAndProcessGroupsSmallInstance(groupFilters, mirrorMapping)
2021
}

internal/mirroring/get_project.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
//
1717
// The function is run in a goroutine for each project, and a wait group is used to wait for all goroutines to finish.
1818
func (g *GitlabInstance) fetchAndProcessProjects(projectFilters *map[string]struct{}, groupFilters *map[string]struct{}, mirrorMapping *utils.MirrorMapping) error {
19+
zap.L().Debug("Fetching and processing projects from GitLab instance", zap.String(ROLE, g.Role), zap.String(INSTANCE_SIZE, g.InstanceSize), zap.Int("projects", len(*projectFilters)), zap.Int("groups", len(*groupFilters)))
1920
if !g.isBig() {
2021
return g.fetchAndProcessProjectsSmallInstance(projectFilters, groupFilters, mirrorMapping)
2122
}

internal/mirroring/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
// It then processes the filters for groups and projects, and finally creates the groups and projects in the destination GitLab instance.
1717
// If the dry run flag is set, it will only print the groups and projects that would be created or updated.
1818
func MirrorGitlabs(gitlabMirrorArgs *utils.ParserArgs) error {
19+
zap.L().Info("Starting GitLab mirroring process", zap.String(ROLE_SOURCE, gitlabMirrorArgs.SourceGitlabURL), zap.String(ROLE_DESTINATION, gitlabMirrorArgs.DestinationGitlabURL))
1920
sourceGitlabSize := INSTANCE_SIZE_SMALL
2021
if gitlabMirrorArgs.SourceGitlabIsBig {
2122
sourceGitlabSize = INSTANCE_SIZE_BIG
@@ -89,6 +90,7 @@ func MirrorGitlabs(gitlabMirrorArgs *utils.ParserArgs) error {
8990
// processFilters processes the filters for groups and projects.
9091
// It returns four maps: sourceProjectFilters, sourceGroupFilters, destinationProjectFilters, and destinationGroupFilters.
9192
func processFilters(filters *utils.MirrorMapping) (map[string]struct{}, map[string]struct{}, map[string]struct{}, map[string]struct{}) {
93+
zap.L().Info("Checking mirror mapping filters")
9294
sourceProjectFilters := make(map[string]struct{})
9395
sourceGroupFilters := make(map[string]struct{})
9496
destinationProjectFilters := make(map[string]struct{})

internal/mirroring/post.go

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import (
1111
"go.uber.org/zap"
1212
)
1313

14+
// ============================================================ //
15+
// GROUP CREATION FUNCTIONS //
16+
// ============================================================ //
17+
1418
// createGroups creates GitLab groups in the destination GitLab instance based on the mirror mapping.
1519
// It retrieves the source group path for each destination group and creates the group in the destination instance.
1620
// The function also handles the copying of group avatars from the source to the destination instance.
1721
func (destinationGitlab *GitlabInstance) createGroups(sourceGitlab *GitlabInstance, mirrorMapping *utils.MirrorMapping) error {
18-
zap.L().Debug("Creating groups in GitLab Instance", zap.String(ROLE, ROLE_DESTINATION))
22+
zap.L().Info("Creating groups in GitLab Instance", zap.String(ROLE, ROLE_DESTINATION))
1923

2024
// Reverse the mirror mapping to get the source group path for each destination group
2125
reversedMirrorMap, destinationGroupPaths := sourceGitlab.reverseGroupMirrorMap(mirrorMapping)
@@ -71,10 +75,48 @@ func (destinationGitlab *GitlabInstance) createGroup(destinationGroupPath string
7175
return destinationGroup, nil
7276
}
7377

78+
// createGroupFromSource creates a GitLab group in the destination GitLab instance based on the source group.
79+
// It sets the group name, path, description, visibility, and default branch based on the source group.
80+
// The function also handles the setting of the parent ID for the group.
81+
// It returns the created group or an error if the creation fails.
82+
func (g *GitlabInstance) createGroupFromSource(sourceGroup *gitlab.Group, copyOptions *utils.MirroringOptions) (*gitlab.Group, error) {
83+
groupCreationArgs := &gitlab.CreateGroupOptions{
84+
Name: &sourceGroup.Name,
85+
Path: &sourceGroup.Path,
86+
Description: &sourceGroup.Description,
87+
Visibility: &sourceGroup.Visibility,
88+
DefaultBranch: &sourceGroup.DefaultBranch,
89+
}
90+
91+
// Retrieve the parent namespace ID for the group
92+
// This is used to set the parent ID for the group
93+
zap.L().Debug("Retrieving group namespace ID", zap.String(ROLE, ROLE_DESTINATION), zap.String(ROLE_DESTINATION, copyOptions.DestinationPath))
94+
parentGroupID, err := g.getParentNamespaceID(copyOptions.DestinationPath)
95+
if err != nil {
96+
return nil, err
97+
} else if parentGroupID >= 0 {
98+
groupCreationArgs.ParentID = &parentGroupID
99+
}
100+
101+
// Create the group in the destination GitLab instance
102+
zap.L().Debug("Creating group in GitLab Instance", zap.String(ROLE, ROLE_DESTINATION), zap.String(ROLE_DESTINATION, copyOptions.DestinationPath))
103+
destinationGroup, _, err := g.Gitlab.Groups.CreateGroup(groupCreationArgs)
104+
if err == nil {
105+
zap.L().Info("Group created", zap.String("group", destinationGroup.WebURL))
106+
g.addGroup(destinationGroup)
107+
}
108+
109+
return destinationGroup, err
110+
}
111+
112+
// ============================================================ //
113+
// PROJECT CREATION FUNCTIONS //
114+
// ============================================================ //
115+
74116
// createProjects creates GitLab projects in the destination GitLab instance based on the mirror mapping.
75117
// It retrieves the source project path for each destination project and creates the project in the destination instance.
76118
func (destinationGitlab *GitlabInstance) createProjects(sourceGitlab *GitlabInstance, mirrorMapping *utils.MirrorMapping) error {
77-
zap.L().Debug("Creating projects in GitLab Instance", zap.String(ROLE, ROLE_DESTINATION))
119+
zap.L().Info("Creating projects in GitLab Instance", zap.String(ROLE, ROLE_DESTINATION))
78120

79121
// Create a wait group to wait for all goroutines to finish
80122
var wg sync.WaitGroup
@@ -171,46 +213,16 @@ func (g *GitlabInstance) createProjectFromSource(sourceProject *gitlab.Project,
171213
zap.L().Debug("Creating project in GitLab Instance", zap.String(ROLE, ROLE_DESTINATION), zap.String(ROLE_DESTINATION, copyOptions.DestinationPath))
172214
destinationProject, _, err := g.Gitlab.Projects.CreateProject(projectCreationArgs)
173215
if err == nil {
174-
zap.L().Debug("Project created", zap.String("project", destinationProject.HTTPURLToRepo))
216+
zap.L().Info("Project created", zap.String("project", destinationProject.HTTPURLToRepo))
175217
g.addProject(destinationProject)
176218
}
177219

178220
return destinationProject, nil
179221
}
180222

181-
// createGroupFromSource creates a GitLab group in the destination GitLab instance based on the source group.
182-
// It sets the group name, path, description, visibility, and default branch based on the source group.
183-
// The function also handles the setting of the parent ID for the group.
184-
// It returns the created group or an error if the creation fails.
185-
func (g *GitlabInstance) createGroupFromSource(sourceGroup *gitlab.Group, copyOptions *utils.MirroringOptions) (*gitlab.Group, error) {
186-
groupCreationArgs := &gitlab.CreateGroupOptions{
187-
Name: &sourceGroup.Name,
188-
Path: &sourceGroup.Path,
189-
Description: &sourceGroup.Description,
190-
Visibility: &sourceGroup.Visibility,
191-
DefaultBranch: &sourceGroup.DefaultBranch,
192-
}
193-
194-
// Retrieve the parent namespace ID for the group
195-
// This is used to set the parent ID for the group
196-
zap.L().Debug("Retrieving group namespace ID", zap.String(ROLE, ROLE_DESTINATION), zap.String(ROLE_DESTINATION, copyOptions.DestinationPath))
197-
parentGroupID, err := g.getParentNamespaceID(copyOptions.DestinationPath)
198-
if err != nil {
199-
return nil, err
200-
} else if parentGroupID >= 0 {
201-
groupCreationArgs.ParentID = &parentGroupID
202-
}
203-
204-
// Create the group in the destination GitLab instance
205-
zap.L().Debug("Creating group in GitLab Instance", zap.String(ROLE, ROLE_DESTINATION), zap.String(ROLE_DESTINATION, copyOptions.DestinationPath))
206-
destinationGroup, _, err := g.Gitlab.Groups.CreateGroup(groupCreationArgs)
207-
if err == nil {
208-
zap.L().Debug("Group created", zap.String("group", destinationGroup.WebURL))
209-
g.addGroup(destinationGroup)
210-
}
211-
212-
return destinationGroup, err
213-
}
223+
// ============================================================ //
224+
// RELEASES CREATION FUNCTIONS //
225+
// ============================================================ //
214226

215227
// mirrorReleases mirrors releases from the source project to the destination project.
216228
// It fetches existing releases from the destination project and creates new releases for those that do not exist.
@@ -279,6 +291,10 @@ func (destinationGitlab *GitlabInstance) mirrorReleases(sourceGitlab *GitlabInst
279291
return utils.MergeErrors(errorChan, 2)
280292
}
281293

294+
// ============================================================ //
295+
// CI/CD CATALOG FUNCTIONS //
296+
// ============================================================ //
297+
282298
// addProjectToCICDCatalog adds a project to the CI/CD catalog in the destination GitLab instance.
283299
// It uses a GraphQL mutation to create the catalog resource for the project.
284300
func (g *GitlabInstance) addProjectToCICDCatalog(project *gitlab.Project) error {

0 commit comments

Comments
 (0)