Skip to content

refactor: reorganize package structure#84

Merged
ravisuhag merged 1 commit intomainfrom
refactor/reorganize-package-structure
Mar 27, 2026
Merged

refactor: reorganize package structure#84
ravisuhag merged 1 commit intomainfrom
refactor/reorganize-package-structure

Conversation

@ravisuhag
Copy link
Copy Markdown
Member

@ravisuhag ravisuhag commented Mar 27, 2026

Summary

  • telemetry/observability/: Merged log/ into observability/logger/, moved otel sub-packages alongside
  • jsondiff/, rql/data/: Grouped data processing utilities under a common parent
  • utils/ deleted: Inlined gRPC status helpers into observability/otelgrpc/status.go
  • otelhhtpclient typo fixedotelhttpclient
  • All internal imports updated, README rewritten to match actual package names

Test plan

  • go build ./... compiles cleanly
  • Verify CI passes (lint + tests)
  • Downstream consumers update import paths

Summary by CodeRabbit

  • Documentation

    • Updated README with reorganized package structure and corrected naming conventions.
  • Refactor

    • Reorganized internal packages under observability, data, and cli namespaces for improved code organization.
    • Updated logging infrastructure across the codebase to align with new package structure.

- telemetry/ → observability/ (with log/ merged as observability/logger/)
- jsondiff/, rql/ → data/jsondiff/, data/rql/
- Fix otelhhtpclient typo → otelhttpclient
- Inline utils/error_status into observability/otelgrpc/status.go, delete utils/
- Rename log package to logger to match directory
- Update all internal imports and README
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

This PR reorganizes and relocates multiple packages: logobservability/logger, telemetryobservability, jsondiffdata/jsondiff, dockertestxtesting/dockertestx. Updates include renaming package declarations, changing import paths across source and test files, updating function signatures where logger types changed, and refreshing documentation and README references.

Changes

Cohort / File(s) Summary
Logger package relocation
observability/logger/logger.go, observability/logger/logrus.go, observability/logger/logrus_test.go, observability/logger/noop.go, observability/logger/zap.go, observability/logger/zap_test.go
Renamed package from log to logger and updated all imports from github.com/raystack/salt/log to github.com/raystack/salt/observability/logger. Updated all function calls and constructor references (e.g., log.NewLogrus()logger.NewLogrus()). Test package names updated accordingly.
Observability package rename
observability/opentelemetry.go, observability/telemetry.go
Renamed package from telemetry to observability. Updated logger parameter types from log.Logger to logger.Logger in function signatures (initOTLP, initGlobalMetrics, initGlobalTracer, and Init). Updated imports to use new logger path.
OTEL subpackages
observability/otelgrpc/otelgrpc.go, observability/otelgrpc/otelgrpc_test.go, observability/otelgrpc/status.go, observability/otelgrpc/status_test.go, observability/otelhttpclient/http_transport.go, observability/otelhttpclient/http_transport_test.go
Updated meter namespace from telemetry/ path to observability/ path. Moved StatusText and StatusCode functions from utils package to otelgrpc package. Updated test imports to reflect new package locations.
Testing and audit modules
testing/dockertestx/postgres.go, auth/audit/repositories/dockertest_test.go, auth/audit/repositories/postgres_test.go
Updated logger type from log.Logger to logger.Logger in function signatures and struct fields. Updated imports from github.com/raystack/salt/log to github.com/raystack/salt/observability/logger. Replaced log.NewLogrus() with logger.NewLogrus().
Documentation updates
README.md, data/jsondiff/README.md
Updated README package listings with new location names (e.g., cli/cmdxcli/commander, cli/promptcli/prompter). Fixed typo "Pacakages" → "Packages". Updated jsondiff import documentation from github.com/raystack/salt/jsondiff to github.com/raystack/salt/data/jsondiff.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop along, dear code, to homes so new and neat,
From log to logger, what a tidy retreat!
Through observability paths, the packages do slide,
With imports reorganized with rabbity pride,
All signatures updated, the refactoring's complete!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% 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 title 'refactor: reorganize package structure' accurately reflects the main change: a comprehensive reorganization of the codebase's package structure, including moving packages (telemetry→observability, jsondiff→data/jsondiff), merging packages (log→observability/logger), and renaming directories to match package names.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/reorganize-package-structure

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
Copy Markdown

@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

Caution

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

⚠️ Outside diff range comments (1)
data/jsondiff/README.md (1)

26-32: ⚠️ Potential issue | 🟡 Minor

Remove unused strings import from both Go examples.
As written, these snippets include an unused import and won’t compile when copied as-is.

✂️ Proposed doc fix
 import (
     "encoding/json"
     "fmt"
     "reflect"
-    "strings"
     "github.com/raystack/salt/data/jsondiff"
 )

Also applies to: 103-109

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@data/jsondiff/README.md` around lines 26 - 32, The Go examples import the
"strings" package but never use it, causing compilation errors; remove the
unused "strings" import from both import blocks in the README examples (the
import lists that currently include "encoding/json", "fmt", "reflect",
"strings", "github.com/raystack/salt/data/jsondiff") so that only used packages
remain (e.g., "encoding/json", "fmt", "reflect",
"github.com/raystack/salt/data/jsondiff").
🧹 Nitpick comments (1)
observability/logger/logrus_test.go (1)

21-72: Consider extracting a shared test logger helper to remove duplication.

The same NewLogrus(...WithLevel...WithWriter...WithFormatter...) setup is repeated in every subtest.

♻️ Suggested refactor
 func TestLogrus(t *testing.T) {
+	newTestLogger := func(level string, w *bufio.Writer) logger.Logger {
+		return logger.NewLogrus(
+			logger.LogrusWithLevel(level),
+			logger.LogrusWithWriter(w),
+			logger.LogrusWithFormatter(&logrus.TextFormatter{DisableTimestamp: true}),
+		)
+	}
+
 	t.Run("should parse info messages at debug level correctly", func(t *testing.T) {
 		var b bytes.Buffer
 		foo := bufio.NewWriter(&b)
-
-		logger := logger.NewLogrus(logger.LogrusWithLevel("debug"), logger.LogrusWithWriter(foo), logger.LogrusWithFormatter(&logrus.TextFormatter{
-			DisableTimestamp: true,
-		}))
+		logger := newTestLogger("debug", foo)
 		logger.Info("hello world")
 		foo.Flush()
@@
 	t.Run("should not parse debug messages at info level correctly", func(t *testing.T) {
 		var b bytes.Buffer
 		foo := bufio.NewWriter(&b)
-
-		logger := logger.NewLogrus(logger.LogrusWithLevel("info"), logger.LogrusWithWriter(foo), logger.LogrusWithFormatter(&logrus.TextFormatter{
-			DisableTimestamp: true,
-		}))
+		logger := newTestLogger("info", foo)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@observability/logger/logrus_test.go` around lines 21 - 72, Extract a small
test helper (e.g., newTestLogger or setupTestLogger) that returns the created
logger and its underlying bufio.Writer/bytes.Buffer pair to eliminate repeated
setup calls; move the repeated NewLogrus(logger.LogrusWithLevel(...),
logger.LogrusWithWriter(...), logger.LogrusWithFormatter(...)) logic into that
helper and update each subtest to call the helper and use the returned logger
and writer before calling foo.Flush() and reading buffer contents. Ensure the
helper uses the same parameters (DisableTimestamp: true) and exposes the buffer
for assertions so tests like those invoking NewLogrus, LogrusWithLevel,
LogrusWithWriter, and LogrusWithFormatter remain unchanged except for using the
helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@observability/otelgrpc/otelgrpc.go`:
- Line 32: The struct tag on meterOptions.meterName isn't applied automatically,
so update NewMeter to use the intended default when meterOpts.meterName is
empty: detect when meterOptions.meterName == "" inside NewMeter and set it to
"github.com/raystack/salt/observability/otelgrpc" before calling otel.Meter;
alternatively initialize meterOptions with that default in the meterOptions
creation path so otel.Meter never receives an empty string. Ensure references
are to meterOptions.meterName and the NewMeter function.

---

Outside diff comments:
In `@data/jsondiff/README.md`:
- Around line 26-32: The Go examples import the "strings" package but never use
it, causing compilation errors; remove the unused "strings" import from both
import blocks in the README examples (the import lists that currently include
"encoding/json", "fmt", "reflect", "strings",
"github.com/raystack/salt/data/jsondiff") so that only used packages remain
(e.g., "encoding/json", "fmt", "reflect",
"github.com/raystack/salt/data/jsondiff").

---

Nitpick comments:
In `@observability/logger/logrus_test.go`:
- Around line 21-72: Extract a small test helper (e.g., newTestLogger or
setupTestLogger) that returns the created logger and its underlying
bufio.Writer/bytes.Buffer pair to eliminate repeated setup calls; move the
repeated NewLogrus(logger.LogrusWithLevel(...), logger.LogrusWithWriter(...),
logger.LogrusWithFormatter(...)) logic into that helper and update each subtest
to call the helper and use the returned logger and writer before calling
foo.Flush() and reading buffer contents. Ensure the helper uses the same
parameters (DisableTimestamp: true) and exposes the buffer for assertions so
tests like those invoking NewLogrus, LogrusWithLevel, LogrusWithWriter, and
LogrusWithFormatter remain unchanged except for using the helper.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e466f661-55be-4c13-aac3-b42d77fd8993

📥 Commits

Reviewing files that changed from the base of the PR and between 91ffa37 and 32efeba.

📒 Files selected for processing (28)
  • README.md
  • auth/audit/repositories/dockertest_test.go
  • auth/audit/repositories/postgres_test.go
  • data/jsondiff/README.md
  • data/jsondiff/jsondiff.go
  • data/jsondiff/jsondiff_test.go
  • data/jsondiff/jsondiff_wi2l.go
  • data/jsondiff/jsondiff_wi2l_test.go
  • data/jsondiff/reconstructor.go
  • data/rql/README.md
  • data/rql/parser.go
  • data/rql/parser_test.go
  • observability/logger/logger.go
  • observability/logger/logrus.go
  • observability/logger/logrus_test.go
  • observability/logger/noop.go
  • observability/logger/zap.go
  • observability/logger/zap_test.go
  • observability/opentelemetry.go
  • observability/otelgrpc/otelgrpc.go
  • observability/otelgrpc/otelgrpc_test.go
  • observability/otelgrpc/status.go
  • observability/otelgrpc/status_test.go
  • observability/otelhttpclient/annotations.go
  • observability/otelhttpclient/http_transport.go
  • observability/otelhttpclient/http_transport_test.go
  • observability/telemetry.go
  • testing/dockertestx/postgres.go

}
type MeterOpts struct {
meterName string `default:"github.com/raystack/salt/telemetry/otelgrpc"`
meterName string `default:"github.com/raystack/salt/observability/otelgrpc"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify where NewMeter is used and whether WithMeterName is passed at call sites.
rg -nP --type=go '\bNewMeter\s*\('
rg -nP --type=go '\bWithMeterName\s*\('

Repository: raystack/salt

Length of output: 233


🏁 Script executed:

# First, let's read the otelgrpc.go file to understand the actual implementation
cat -n observability/otelgrpc/otelgrpc.go

Repository: raystack/salt

Length of output: 6255


🏁 Script executed:

# Find all call sites of NewMeter across the repository
rg -A2 '\bNewMeter\(' --type=go

Repository: raystack/salt

Length of output: 271


🏁 Script executed:

# Check if there's any struct tag processing (reflect, struct tag parsing) in the file
rg -n 'reflect|struct|tag|default' observability/otelgrpc/otelgrpc.go --type=go

Repository: raystack/salt

Length of output: 216


🏁 Script executed:

# Search for all NewMeter call sites across the entire repository
rg 'NewMeter' --type=go -B2 -A2

Repository: raystack/salt

Length of output: 755


🏁 Script executed:

# Check if there's any struct tag processing library imported or used
rg 'reflect|defaults|struct' observability/otelgrpc/otelgrpc.go -A2 -B2

Repository: raystack/salt

Length of output: 373


🏁 Script executed:

# Find test files related to otelgrpc
fd -e test.go -e _test.go observability

Repository: raystack/salt

Length of output: 39


🏁 Script executed:

# Check all imports in otelgrpc.go to confirm no struct tag processing library
head -20 observability/otelgrpc/otelgrpc.go

Repository: raystack/salt

Length of output: 429


🏁 Script executed:

# One final check: search for any usage of WithMeterName in tests or examples
rg 'WithMeterName' --type=go -B3 -A3

Repository: raystack/salt

Length of output: 443


Default meter name is not actually applied in NewMeter.

Line 32's struct tag default does not initialize meterOpts.meterName; NewMeter still starts with an empty value on Line 42, so otel.Meter(...) on Line 46 receives "" unless an option is passed. Go does not automatically process struct tag defaults—they are pure metadata.

Proposed fix
 type MeterOpts struct {
-	meterName string `default:"github.com/raystack/salt/observability/otelgrpc"`
+	meterName string
 }
+
+const defaultMeterName = "github.com/raystack/salt/observability/otelgrpc"
 
 func NewMeter(hostName string, opts ...Option) Meter {
-	meterOpts := &MeterOpts{}
+	meterOpts := &MeterOpts{meterName: defaultMeterName}
 	for _, opt := range opts {
 		opt(meterOpts)
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@observability/otelgrpc/otelgrpc.go` at line 32, The struct tag on
meterOptions.meterName isn't applied automatically, so update NewMeter to use
the intended default when meterOpts.meterName is empty: detect when
meterOptions.meterName == "" inside NewMeter and set it to
"github.com/raystack/salt/observability/otelgrpc" before calling otel.Meter;
alternatively initialize meterOptions with that default in the meterOptions
creation path so otel.Meter never receives an empty string. Ensure references
are to meterOptions.meterName and the NewMeter function.

@ravisuhag ravisuhag merged commit b213c35 into main Mar 27, 2026
4 checks passed
@ravisuhag ravisuhag deleted the refactor/reorganize-package-structure branch March 27, 2026 12:23
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.

2 participants