<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #38889 PLEASE READ BELOW before looking at file changes Before converting individual files/packages to slog, we generally need to make these 2 changes to make the conversion easier: - Replace uses of `kitlog.With` since they are not fully compatible with our kitlog adapter - Directly use the kitlog adapter logger type instead of the kitlog interface, which will let us have direct access to the underlying slog logger: `*logging.Logger` Note: that I did not replace absolutely all uses of `kitlog.Logger`, but I did remove all uses of `kitlog.With` except for these due to complexity: - server/logging/filesystem.go and the other log writers (webhook, firehose, kinesis, lambda, pubsub, nats) - server/datastore/mysql/nanomdm_storage.go (adapter pattern) - server/vulnerabilities/nvd/* (cascades to CLI tools) - server/service/osquery_utils/queries.go (callback type signatures cascade broadly) - cmd/maintained-apps/ (standalone, so can be transitioned later all at once) Most of the changes in this PR follow these patterns: - `kitlog.Logger` type → `*logging.Logger` - `kitlog.With(logger, ...)` → `logger.With(...)` - `kitlog.NewNopLogger() → logging.NewNopLogger()`, including similar variations such as `logging.NewLogfmtLogger(w)` and `logging.NewJSONLogger(w)` - removed many now-unused kitlog imports Unique changes that the PR review should focus on: - server/platform/logging/kitlog_adapter.go: Core adapter changes - server/platform/logging/logging.go: New convenience functions - server/service/integration_logger_test.go: Test changes for slog # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. - Was added in previous PR ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Migrated the codebase to a unified internal structured logging system for more consistent, reliable logs and observability. * No user-facing functionality changed; runtime behavior and APIs remain compatible. * **Tests** * Updated tests to use the new logging helpers to ensure consistent test logging and validation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
87 lines
2.6 KiB
Go
87 lines
2.6 KiB
Go
//go:build !windows
|
|
|
|
// Windows is disabled because the TPM simulator requires CGO, which causes lint failures on Windows.
|
|
|
|
package hostidentity
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/config"
|
|
"github.com/fleetdm/fleet/v4/server/datastore/redis/redistest"
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/fleetdm/fleet/v4/server/platform/logging"
|
|
"github.com/fleetdm/fleet/v4/server/service"
|
|
"github.com/fleetdm/fleet/v4/server/service/integrationtest"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// enrollOrbitResponse is the response structure for orbit enrollment
|
|
type enrollOrbitResponse struct {
|
|
OrbitNodeKey string `json:"orbit_node_key,omitempty"`
|
|
Err error `json:"error,omitempty"`
|
|
}
|
|
|
|
// orbitConfigRequest is used for orbit config endpoint requests
|
|
type orbitConfigRequest struct {
|
|
OrbitNodeKey string `json:"orbit_node_key"`
|
|
}
|
|
|
|
// osqueryConfigRequest is used for osquery config endpoint requests
|
|
type osqueryConfigRequest struct {
|
|
NodeKey string `json:"node_key"`
|
|
}
|
|
|
|
type Suite struct {
|
|
integrationtest.BaseSuite
|
|
}
|
|
|
|
func SetUpSuite(t *testing.T, uniqueTestName string, requireSignature bool) *Suite {
|
|
return SetUpSuiteWithConfig(t, uniqueTestName, requireSignature, nil)
|
|
}
|
|
|
|
func SetUpSuiteWithConfig(t *testing.T, uniqueTestName string, requireSignature bool, configModifier func(cfg *config.FleetConfig)) *Suite {
|
|
// Note: t.Parallel() is called when MySQL datastore options are processed
|
|
license := &fleet.LicenseInfo{
|
|
Tier: fleet.TierPremium,
|
|
}
|
|
ds, fleetCfg, fleetSvc, ctx := integrationtest.SetUpMySQLAndService(t, uniqueTestName, &service.TestServerOpts{
|
|
License: license,
|
|
Pool: redistest.SetupRedis(t, t.Name(), false, false, false),
|
|
})
|
|
|
|
// Apply config modifications
|
|
if configModifier != nil {
|
|
configModifier(&fleetCfg)
|
|
}
|
|
|
|
logger := logging.NewLogfmtLogger(os.Stdout)
|
|
hostIdentitySCEPDepot, err := ds.NewHostIdentitySCEPDepot(logger.With("component", "host-id-scep-depot"), &fleetCfg)
|
|
require.NoError(t, err)
|
|
users, server := service.RunServerForTestsWithServiceWithDS(t, ctx, ds, fleetSvc, &service.TestServerOpts{
|
|
License: license,
|
|
FleetConfig: &fleetCfg,
|
|
Logger: logger,
|
|
HostIdentity: &service.HostIdentity{
|
|
SCEPStorage: hostIdentitySCEPDepot,
|
|
RequireHTTPMessageSignature: requireSignature,
|
|
},
|
|
})
|
|
|
|
s := &Suite{
|
|
BaseSuite: integrationtest.BaseSuite{
|
|
Logger: logger,
|
|
DS: ds,
|
|
FleetCfg: fleetCfg,
|
|
Users: users,
|
|
Server: server,
|
|
},
|
|
}
|
|
|
|
integrationtest.SetUpServerURL(t, ds, server)
|
|
|
|
s.BaseSuite.Token = s.BaseSuite.GetTestAdminToken(t)
|
|
return s
|
|
}
|