Skip to content

Conversation

@isasmendiagus
Copy link
Contributor

@isasmendiagus isasmendiagus commented Jan 27, 2026

Summary

  • Add database version info (schema_version, created_at) to the StatusResponse across all component service endpoints
  • Add server version to the StatusResponse
  • When the db_version table is not available (e.g., older Sqlite databases), the db field is omitted from the response

Dependencies

This PR depends on the following PRs being merged and tagged with their next minor version:

Summary by CodeRabbit

  • New Features

    • Status responses now include server version and database schema metadata; server logs DB version info on startup when available.
  • Tests

    • Automated tests updated to expect and validate the added version metadata in status responses.
  • Chores

    • Added APP_VERSION configuration, adjusted startup wiring, and updated ignore patterns; dependency bumps recorded.
  • Documentation

    • CHANGELOG updated with a 0.7.0 release entry describing these changes.

✏️ Tip: You can customize this high-level summary in your review settings.

@isasmendiagus isasmendiagus requested a review from eeisegn January 27, 2026 17:44
@coderabbitai
Copy link

coderabbitai bot commented Jan 27, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds server and per-response version metadata: server reads app (embedded) version and DB schema version, logs DB version on startup, and enriches component service responses with Server and Db fields. Dependency upgrades and config addition for APP_VERSION included.

Changes

Cohort / File(s) Summary
Dependency Management
go.mod
Added github.com/scanoss/go-models v0.4.0; upgraded github.com/scanoss/go-grpc-helper and github.com/scanoss/papi.
Server bootstrap
pkg/cmd/server.go
Set cfg.App.Version from embedded version when unset; instantiate DB version model, fetch/log DB schema/version on startup; call RunServer without explicit version arg.
gRPC server
pkg/protocol/grpc/server.go
Removed version parameter from RunServer signature; telemetry initialization now uses config.App.Version.
Service implementation
pkg/service/component_service.go
componentServer now holds dbVersionModel; NewComponentServer initializes it; added getDBVersion(); all responses (errors/success) populate StatusResponse with Db and Server metadata.
Service tests
pkg/service/component_service_test.go
Tests set myConfig.App.Version = "test-version" and updated expected Status responses to include Server.Version.
Config
pkg/config/server_config.go
Added App.Version string \env:"APP_VERSION"`toServerConfig`.
Changelog & Misc
CHANGELOG.md, .gitignore
Added [0.7.0] changelog entry documenting version/DB metadata changes; updated .gitignore to ignore config/*test*.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ComponentServer as Component Server
    participant Database
    participant Telemetry

    Client->>ComponentServer: Request (SearchComponents / GetComponentVersions)
    activate ComponentServer
    ComponentServer->>Database: Query component data
    Database-->>ComponentServer: Component data / error
    ComponentServer->>Database: Query db_version table (getDBVersion)
    Database-->>ComponentServer: DB schema_version / created_at / empty/error
    ComponentServer->>Telemetry: Record timing (uses config.App.Version)
    Note over ComponentServer: Build StatusResponse with Data, Status, Db{schema_version,created_at}, Server{version}
    ComponentServer-->>Client: StatusResponse {Data, Status, Db, Server}
    deactivate ComponentServer
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped through configs, logs, and time,
Found schema stamps and a version rhyme.
Responses now wear badges neat,
Startup greets the DB heartbeat.
Tiny hops, clearer trails — yum!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately and specifically describes the main change: adding database version information to status responses in the service layer.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/SP-3636/add-db-version-to-status-response

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@go.mod`:
- Around line 13-16: The build is failing because go.sum is missing checksums
for the newly added modules (github.com/scanoss/go-grpc-helper,
github.com/scanoss/go-models, github.com/scanoss/go-purl-helper,
github.com/scanoss/papi); run `go mod tidy` in the module root to download and
verify those dependencies and regenerate go.sum, then commit the updated go.sum
so CI can pass.
🧹 Nitpick comments (1)
pkg/service/component_service.go (1)

175-186: Consider passing the request context for better observability.

Using context.Background() loses request tracing and cancellation signals. For consistency with observability practices and to allow the DB query to be cancelled if the request is cancelled, consider passing the context from the caller.

♻️ Suggested refactor
-func (d componentServer) getDBVersion() *common.StatusResponse_DB {
-	dbVersion, err := d.dbVersionModel.GetCurrentVersion(context.Background())
+func (d componentServer) getDBVersion(ctx context.Context) *common.StatusResponse_DB {
+	dbVersion, err := d.dbVersionModel.GetCurrentVersion(ctx)
 	if err != nil || len(dbVersion.SchemaVersion) == 0 {
 		return nil
 	}
 	return &common.StatusResponse_DB{
 		SchemaVersion: dbVersion.SchemaVersion,
 		CreatedAt:     dbVersion.CreatedAt,
 	}
 }

Then update all call sites to pass ctx:

status.Db = d.getDBVersion(ctx)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
pkg/cmd/server.go (2)

24-32: ⚠️ Potential issue | 🟠 Major

Update go.sum: missing entries for github.com/scanoss/go-models and github.com/scanoss/go-grpc-helper

The go.mod file declares both github.com/scanoss/go-models v0.3.0 and github.com/scanoss/go-grpc-helper v0.11.0 in the require block, but go.sum is missing the corresponding checksums for these modules. Run go mod tidy to sync go.sum with go.mod.


19-31: ⚠️ Potential issue | 🟡 Minor

Suppress ErrTableNotFound noise in startup DB version logging.

The changelog for v0.7.0 explicitly states "Log error when querying db version fails with an error other than ErrTableNotFound", but the current code at lines 116-125 warns on any error. The codebase already uses the correct pattern elsewhere (e.g., pkg/service/component_service.go).

🐛 Suggested fix
 import (
 	"context"
 	_ "embed"
+	"errors"
 	"flag"
 	"fmt"
 	defer gd.CloseDBConnection(db)
 	// Log database version info
 	dbVersionModel := gomodels.NewDBVersionModel(db)
 	dbVersion, dbVersionErr := dbVersionModel.GetCurrentVersion(context.Background())
 	if dbVersionErr != nil {
-		zlog.S.Warnf("Could not read db_version table: %v", dbVersionErr)
+		if !errors.Is(dbVersionErr, gomodels.ErrTableNotFound) {
+			zlog.S.Warnf("Could not read db_version table: %v", dbVersionErr)
+		}
 	} else if len(dbVersion.SchemaVersion) > 0 {
🧹 Nitpick comments (2)
CHANGELOG.md (1)

8-22: Consider clearing the “Upcoming changes...” placeholder under Unreleased.
Optional doc cleanup now that 0.7.0 is published.

Also applies to: 42-42

pkg/service/component_service.go (1)

174-191: Prefer request context in DB version lookup for cancellation/log context.
Right now it always uses context.Background(), which drops request-scoped metadata. Consider passing ctx into getDBVersion and using it for DB calls and logging.

♻️ Suggested update
-func (d componentServer) getDBVersion() *common.StatusResponse_DB {
-	dbVersion, err := d.dbVersionModel.GetCurrentVersion(context.Background())
+func (d componentServer) getDBVersion(ctx context.Context) *common.StatusResponse_DB {
+	if ctx == nil {
+		ctx = context.Background()
+	}
+	dbVersion, err := d.dbVersionModel.GetCurrentVersion(ctx)
 	if err != nil {
 		if !errors.Is(err, gomodels.ErrTableNotFound) {
-			s := ctxzap.Extract(context.Background()).Sugar()
+			s := ctxzap.Extract(ctx).Sugar()
 			s.Errorf("Failed to get db version: %v", err)
 		}
 		return nil
 	}

Update callers to pass the request ctx (e.g., status.Db = d.getDBVersion(ctx)).

@isasmendiagus isasmendiagus merged commit db2a083 into main Jan 30, 2026
2 of 3 checks passed
@isasmendiagus isasmendiagus deleted the feat/SP-3636/add-db-version-to-status-response branch January 30, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants