Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Followup - prevent handleRepositories from crashing | Stop using pointers in logs | Fix fetching service from repo #262

Merged
merged 7 commits into from
Feb 23, 2024

Conversation

taimoorgit
Copy link
Contributor

@taimoorgit taimoorgit commented Feb 21, 2024

Issues

https://github.com/OpsLevel/team-platform/issues/243

#260

Changelog

  • Prevent call to repo.GetService() that crashes if the base directory is nil.
  • Use JSON marshal for logging so that logs aren't full of pointers (that happens when using %+v)
  • Make a changie entry

Tophatting

I am using the sample config on our dev cluster.

On a deployment, I added an annotation that attached a repository.

6:39PM INF [redis] Attached repository '{"service":null,"repository":{"alias":"github.com:jason-opslevel/a_repo"},"baseDirectory":"/","displayName":"My Cool Repo"}'
6:42PM ERR [JSONRPC APIz] Failed assigning repository '{"service":null,"repository":{"alias":"github.com:jason-opslevel/a_repo"},"baseDirectory":"/","displayName":"My Cool Repo"}'
	REASON: OpsLevel API Errors:
	- 'repository' Repository is already linked to this service at this path.

I noticed I could never encounter the path where the repository gets renamed because the code isn't smart enough to know the baseDirectory "/" == "". Had to make this opslevel-go change for that to work: OpsLevel/opslevel-go#374

Result is that repository names actually get updated.

7:06PM INF [JSONRPC APIz] Updated repository '{"service":null,"repository":{"alias":"github.com:jason-opslevel/a_repo"},"baseDirectory":"/","displayName":"Hello Redis"}'

Later run:

7:25PM DBG [JSONRPC APIz] Repository '{"service":null,"repository":{"alias":"github.com:jason-opslevel/a_repo"},"baseDirectory":"/","displayName":"Hello Redis"}' already attached to service ... skipping

An invalid repo doesn't crash the program:

7:30PM ERR [web] Failed assigning repository '{"service":null,"repository":{"alias":"---------------invalidrepo------------------"},"baseDirectory":"/","displayName":"Hello Redis"}'
	REASON: OpsLevel API Errors:
	- 'alias' '---------------invalidrepo------------------' does not identify a repository on this account

@taimoorgit taimoorgit added the bug Something isn't working label Feb 21, 2024
@taimoorgit taimoorgit self-assigned this Feb 21, 2024
@taimoorgit taimoorgit changed the title Followup - prevent handleRepositories from crashing | Stop using pointers in logs Followup - prevent handleRepositories from crashing | Stop using pointers in logs | Fix fetching service from repo Feb 22, 2024
@@ -363,15 +363,26 @@ func (r *ServiceReconciler) handleTools(service *opslevel.Service, registration

func (r *ServiceReconciler) handleRepositories(service *opslevel.Service, registration opslevel_jq_parser.ServiceRegistration) {
for _, repositoryCreate := range registration.Repositories {
if repositoryCreate.Repository.Alias == nil || *repositoryCreate.Repository.Alias == "null" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#36

Checking for string "null" because of this^

@taimoorgit taimoorgit merged commit f7517c5 into main Feb 23, 2024
4 checks passed
@taimoorgit taimoorgit deleted the ta/nil-repo branch February 23, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants