Full rebrand across cosmetic branding, code identifiers, and infrastructure/data-plane naming, using the supplied Cairn OBS logo package. Cosmetic: favicon/logo swap (also closes a stale license-audit finding -- the old favicon was SvelteKit's unreplaced scaffold logo), new centered welcome landing page, larger/legible sidebar logo, page titles, CLAUDE.md/README/docs prose. Code identifiers: Go module path github.com/sentry/sentry -> github.com/cairnobs/cairnobs across all 13 modules and ~91 files (protoc regenerated); Rust crates sentry-agent/sentry-parser/sentry-search -> cairnobs-*; CLI sentryctl -> cairnobsctl; Terraform provider fully renamed (sentry_dashboard etc. -> cairnobs_dashboard, provider type, env vars); every session/auth cookie name; agent config paths and Windows service identity. Deliberately preserved: the gRPC wire protocol's protobuf packages (sentry.logs.v1, sentry.agent.v1) and their Go import directory (proto/sentry/...) -- renaming the wire-level package would break every currently-deployed agent binary (confirmed two real hosts, including mail.inbuxa.com, are actively streaming through this exact contract) until rebuilt and redeployed in lockstep with an ingest cutover. Only the Go module path wrapping the generated code changes. Infrastructure: every docker-compose container name (root and three component-level compose files); the Helm chart (directory, Chart.yaml, named-template helpers, all templates, values.yaml image repos); Kubernetes Operator (CRD group sentry.io -> cairnobs.io, both CRD YAML files, Go identifiers, RBAC markers); the coupled enterprise/tenantcrd package. Caught and fixed real path-coupling bugs along the way: the Helm chart's search/ingest volume mounts and the dev-only-credential detection constant vs. docker-compose.yml's literal values had to move together or a security warning would have silently stopped firing. Data plane: Postgres database sentry_metadata -> cairnobs_metadata and role sentry -> cairnobs; ClickHouse database sentry -> cairnobs; Kafka topic sentry.logs.raw -> cairnobs.logs.raw and its consumer groups. Source-level defaults, docker-compose.yml, and every migrate.sh/ provision script default updated together; already-applied migration files left untouched per this repo's immutable-migration convention. Verified at every layer: all 13 Go modules build/vet/test clean, both Rust workspaces (agent, search) build/clippy/test clean, npm run check/ build clean, docker compose config validates on all four compose files. Live-verified against a real docker stack multiple times through this work, including a final fresh-volume run confirming the actual renamed Postgres database/role, ClickHouse database, and Kafka topic all work end to end with a real login and query, zero console errors.
269 lines
8.8 KiB
Go
269 lines
8.8 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
|
"github.com/hashicorp/terraform-plugin-framework/provider"
|
|
"github.com/hashicorp/terraform-plugin-framework/resource"
|
|
)
|
|
|
|
// TestProviderSchemaValid and TestDashboardResourceSchemaValid don't
|
|
// need a Terraform binary or a live api service -- ValidateImplementation
|
|
// runs the same internal consistency checks
|
|
// terraform-plugin-framework's own protocol layer would (attribute
|
|
// names are valid identifiers, no Optional+Required conflicts, etc.),
|
|
// catching a broken schema before it ever reaches an acceptance test.
|
|
func TestProviderSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := provider.SchemaRequest{}
|
|
resp := &provider.SchemaResponse{}
|
|
|
|
New("test")().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("provider schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{"endpoint", "alerting_endpoint", "token"} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("provider schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDashboardResourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := resource.SchemaRequest{}
|
|
resp := &resource.SchemaResponse{}
|
|
|
|
newDashboardResource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("cairnobs_dashboard schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{
|
|
"id", "tenant_id", "name", "description",
|
|
"default_earliest", "default_latest", "created_by", "created_at", "updated_at",
|
|
} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("cairnobs_dashboard schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
if !resp.Schema.Attributes["name"].IsRequired() {
|
|
t.Error(`"name" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsComputed() {
|
|
t.Error(`"id" must be Computed`)
|
|
}
|
|
}
|
|
|
|
func TestDashboardResourceMetadataSetsTypeName(t *testing.T) {
|
|
resp := &resource.MetadataResponse{}
|
|
newDashboardResource().Metadata(context.Background(), resource.MetadataRequest{ProviderTypeName: "cairnobs"}, resp)
|
|
if resp.TypeName != "cairnobs_dashboard" {
|
|
t.Fatalf("TypeName = %q, want cairnobs_dashboard", resp.TypeName)
|
|
}
|
|
}
|
|
|
|
func TestDashboardPanelResourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := resource.SchemaRequest{}
|
|
resp := &resource.SchemaResponse{}
|
|
|
|
newDashboardPanelResource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("cairnobs_dashboard_panel schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{
|
|
"id", "dashboard_id", "title", "query", "query_language", "viz_type", "viz_config",
|
|
"position_x", "position_y", "width", "height",
|
|
"earliest_override", "latest_override", "sort_order", "created_at", "updated_at",
|
|
} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("cairnobs_dashboard_panel schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
if !resp.Schema.Attributes["query"].IsRequired() {
|
|
t.Error(`"query" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["dashboard_id"].IsRequired() {
|
|
t.Error(`"dashboard_id" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsComputed() {
|
|
t.Error(`"id" must be Computed`)
|
|
}
|
|
}
|
|
|
|
func TestDashboardPanelResourceMetadataSetsTypeName(t *testing.T) {
|
|
resp := &resource.MetadataResponse{}
|
|
newDashboardPanelResource().Metadata(context.Background(), resource.MetadataRequest{ProviderTypeName: "cairnobs"}, resp)
|
|
if resp.TypeName != "cairnobs_dashboard_panel" {
|
|
t.Fatalf("TypeName = %q, want cairnobs_dashboard_panel", resp.TypeName)
|
|
}
|
|
}
|
|
|
|
func TestAlertRuleResourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := resource.SchemaRequest{}
|
|
resp := &resource.SchemaResponse{}
|
|
|
|
newAlertRuleResource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("cairnobs_alert_rule schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{
|
|
"id", "tenant_id", "name", "description", "query", "query_language",
|
|
"condition_type", "comparator", "threshold_value", "eval_interval_seconds",
|
|
"for_minutes", "renotify_interval_minutes", "notification_target_id", "enabled", "created_by",
|
|
} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("cairnobs_alert_rule schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
if !resp.Schema.Attributes["name"].IsRequired() {
|
|
t.Error(`"name" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsComputed() {
|
|
t.Error(`"id" must be Computed`)
|
|
}
|
|
}
|
|
|
|
func TestAlertRuleResourceMetadataSetsTypeName(t *testing.T) {
|
|
resp := &resource.MetadataResponse{}
|
|
newAlertRuleResource().Metadata(context.Background(), resource.MetadataRequest{ProviderTypeName: "cairnobs"}, resp)
|
|
if resp.TypeName != "cairnobs_alert_rule" {
|
|
t.Fatalf("TypeName = %q, want cairnobs_alert_rule", resp.TypeName)
|
|
}
|
|
}
|
|
|
|
func TestNotificationTargetResourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := resource.SchemaRequest{}
|
|
resp := &resource.SchemaResponse{}
|
|
|
|
newNotificationTargetResource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("cairnobs_notification_target schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
for _, attr := range []string{
|
|
"id", "tenant_id", "name", "kind", "webhook_url",
|
|
"payload_template", "headers", "secret", "created_by",
|
|
} {
|
|
if _, ok := resp.Schema.Attributes[attr]; !ok {
|
|
t.Errorf("cairnobs_notification_target schema missing expected attribute %q", attr)
|
|
}
|
|
}
|
|
if !resp.Schema.Attributes["name"].IsRequired() {
|
|
t.Error(`"name" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["secret"].IsSensitive() {
|
|
t.Error(`"secret" must be Sensitive`)
|
|
}
|
|
}
|
|
|
|
func TestNotificationTargetResourceMetadataSetsTypeName(t *testing.T) {
|
|
resp := &resource.MetadataResponse{}
|
|
newNotificationTargetResource().Metadata(context.Background(), resource.MetadataRequest{ProviderTypeName: "cairnobs"}, resp)
|
|
if resp.TypeName != "cairnobs_notification_target" {
|
|
t.Fatalf("TypeName = %q, want cairnobs_notification_target", resp.TypeName)
|
|
}
|
|
}
|
|
|
|
func TestDashboardDataSourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := datasource.SchemaRequest{}
|
|
resp := &datasource.SchemaResponse{}
|
|
|
|
newDashboardDataSource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("cairnobs_dashboard data source schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsRequired() {
|
|
t.Error(`"id" must be Required -- a data source needs it to know what to look up`)
|
|
}
|
|
if !resp.Schema.Attributes["name"].IsComputed() {
|
|
t.Error(`"name" must be Computed`)
|
|
}
|
|
}
|
|
|
|
func TestDashboardPanelDataSourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := datasource.SchemaRequest{}
|
|
resp := &datasource.SchemaResponse{}
|
|
|
|
newDashboardPanelDataSource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("cairnobs_dashboard_panel data source schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
if !resp.Schema.Attributes["dashboard_id"].IsRequired() {
|
|
t.Error(`"dashboard_id" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsRequired() {
|
|
t.Error(`"id" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["query"].IsComputed() {
|
|
t.Error(`"query" must be Computed`)
|
|
}
|
|
}
|
|
|
|
func TestAlertRuleDataSourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := datasource.SchemaRequest{}
|
|
resp := &datasource.SchemaResponse{}
|
|
|
|
newAlertRuleDataSource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("cairnobs_alert_rule data source schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsRequired() {
|
|
t.Error(`"id" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["query"].IsComputed() {
|
|
t.Error(`"query" must be Computed`)
|
|
}
|
|
}
|
|
|
|
func TestNotificationTargetDataSourceSchemaValid(t *testing.T) {
|
|
ctx := context.Background()
|
|
req := datasource.SchemaRequest{}
|
|
resp := &datasource.SchemaResponse{}
|
|
|
|
newNotificationTargetDataSource().Schema(ctx, req, resp)
|
|
|
|
if resp.Diagnostics.HasError() {
|
|
t.Fatalf("cairnobs_notification_target data source schema has errors: %v", resp.Diagnostics)
|
|
}
|
|
if !resp.Schema.Attributes["id"].IsRequired() {
|
|
t.Error(`"id" must be Required`)
|
|
}
|
|
if !resp.Schema.Attributes["secret"].IsSensitive() {
|
|
t.Error(`"secret" must be Sensitive`)
|
|
}
|
|
}
|
|
|
|
func TestDataSourcesMetadataSetTypeNames(t *testing.T) {
|
|
cases := []struct {
|
|
newDS func() datasource.DataSource
|
|
wantType string
|
|
}{
|
|
{newDashboardDataSource, "cairnobs_dashboard"},
|
|
{newDashboardPanelDataSource, "cairnobs_dashboard_panel"},
|
|
{newAlertRuleDataSource, "cairnobs_alert_rule"},
|
|
{newNotificationTargetDataSource, "cairnobs_notification_target"},
|
|
}
|
|
for _, c := range cases {
|
|
resp := &datasource.MetadataResponse{}
|
|
c.newDS().Metadata(context.Background(), datasource.MetadataRequest{ProviderTypeName: "cairnobs"}, resp)
|
|
if resp.TypeName != c.wantType {
|
|
t.Errorf("TypeName = %q, want %q", resp.TypeName, c.wantType)
|
|
}
|
|
}
|
|
}
|