var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import AnalyticsBaseModel from "./AnalyticsBaseModel/AnalyticsBaseModel";
import Route from "../../Types/API/Route";
import AnalyticsTableEngine from "../../Types/AnalyticsDatabase/AnalyticsTableEngine";
import AnalyticsTableName from "../../Types/AnalyticsDatabase/AnalyticsTableName";
import AnalyticsTableColumn, { SkipIndexType, } from "../../Types/AnalyticsDatabase/TableColumn";
import TableColumnType from "../../Types/AnalyticsDatabase/TableColumnType";
import OperationalResource from "../../Types/Database/AccessControl/OperationalResource";
import OwnedThrough from "../../Types/Database/AccessControl/OwnedThrough";
import Permission from "../../Types/Permission";
import Service from "../DatabaseModels/Service";
let ProfileSample = class ProfileSample extends AnalyticsBaseModel {
    constructor() {
        const projectIdColumn = new AnalyticsTableColumn({
            key: "projectId",
            title: "Project ID",
            description: "ID of project",
            required: true,
            type: TableColumnType.ObjectID,
            isTenantId: true,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const primaryEntityIdColumn = new AnalyticsTableColumn({
            key: "primaryEntityId",
            title: "Service ID",
            description: "ID of the resource the profile sample belongs to (Service / Host / DockerHost / KubernetesCluster / Monitor — disambiguated by primaryEntityType)",
            required: true,
            type: TableColumnType.ObjectID,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const primaryEntityTypeColumn = new AnalyticsTableColumn({
            key: "primaryEntityType",
            isLowCardinality: true,
            title: "Service Type",
            description: "Discriminator for primaryEntityId — tells the read side which resource table to dispatch to",
            required: false,
            type: TableColumnType.Text,
            skipIndex: {
                name: "idx_service_type",
                type: SkipIndexType.Set,
                params: [10],
                granularity: 4,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const profileIdColumn = new AnalyticsTableColumn({
            key: "profileId",
            title: "Profile ID",
            description: "FK to profile table",
            required: true,
            type: TableColumnType.Text,
            codec: { codec: "ZSTD", level: 1 },
            skipIndex: {
                name: "idx_profile_id",
                type: SkipIndexType.BloomFilter,
                params: [0.01],
                granularity: 1,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const traceIdColumn = new AnalyticsTableColumn({
            key: "traceId",
            title: "Trace ID",
            description: "Trace correlation (from Link table)",
            required: false,
            type: TableColumnType.Text,
            codec: { codec: "ZSTD", level: 1 },
            skipIndex: {
                name: "idx_trace_id",
                type: SkipIndexType.BloomFilter,
                params: [0.01],
                granularity: 1,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const spanIdColumn = new AnalyticsTableColumn({
            key: "spanId",
            title: "Span ID",
            description: "Span correlation (from Link table)",
            required: false,
            type: TableColumnType.Text,
            codec: { codec: "ZSTD", level: 1 },
            skipIndex: {
                name: "idx_span_id",
                type: SkipIndexType.BloomFilter,
                params: [0.01],
                granularity: 1,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const timeColumn = new AnalyticsTableColumn({
            key: "time",
            codec: [{ codec: "DoubleDelta" }, { codec: "ZSTD", level: 1 }],
            title: "Time",
            description: "Sample timestamp",
            required: true,
            type: TableColumnType.DateTime64,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const timeUnixNanoColumn = new AnalyticsTableColumn({
            key: "timeUnixNano",
            title: "Time (in Unix Nano)",
            description: "Sample timestamp in unix nanoseconds",
            required: true,
            type: TableColumnType.UInt64,
            codec: [{ codec: "DoubleDelta" }, { codec: "ZSTD", level: 1 }],
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const stacktraceColumn = new AnalyticsTableColumn({
            key: "stacktrace",
            title: "Stacktrace",
            description: "Fully-resolved stack frames (function@file:line)",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayText,
            codec: { codec: "ZSTD", level: 3 },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const stacktraceHashColumn = new AnalyticsTableColumn({
            key: "stacktraceHash",
            title: "Stacktrace Hash",
            description: "Hash of stacktrace for grouping",
            required: true,
            type: TableColumnType.Text,
            codec: { codec: "ZSTD", level: 1 },
            skipIndex: {
                name: "idx_stacktrace_hash",
                type: SkipIndexType.BloomFilter,
                params: [0.01],
                granularity: 1,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const frameTypesColumn = new AnalyticsTableColumn({
            key: "frameTypes",
            title: "Frame Types",
            description: "Per-frame runtime type (kernel, native, jvm, cpython, go, v8js, etc.)",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayText,
            codec: { codec: "ZSTD", level: 3 },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const valueColumn = new AnalyticsTableColumn({
            key: "value",
            codec: { codec: "ZSTD", level: 1 },
            title: "Value",
            description: "Sample value (CPU time, bytes, count)",
            required: true,
            type: TableColumnType.UInt64,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const profileTypeColumn = new AnalyticsTableColumn({
            key: "profileType",
            title: "Profile Type",
            description: "Denormalized profile type for filtering",
            required: true,
            type: TableColumnType.Text,
            skipIndex: {
                name: "idx_profile_type",
                type: SkipIndexType.Set,
                params: [20],
                granularity: 4,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const labelsColumn = new AnalyticsTableColumn({
            key: "labels",
            title: "Labels",
            description: "Sample-level labels",
            required: true,
            defaultValue: {},
            type: TableColumnType.MapStringString,
            codec: { codec: "ZSTD", level: 3 },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        const entityKeysColumn = new AnalyticsTableColumn({
            key: "entityKeys",
            codec: { codec: "ZSTD", level: 3 },
            title: "Entity Keys",
            description: "Stable keys of every OpenTelemetry entity (service, host, k8s.pod, container, ...) this signal belongs to. A superset that includes the primary entity. Enables cross-cutting membership queries via has(entityKeys, :key).",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayText,
            skipIndex: {
                name: "idx_entity_keys",
                type: SkipIndexType.BloomFilter,
                params: [0.01],
                granularity: 1,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [],
            },
        });
        /*
         * Scalar per-entity-type key columns — denormalized single-value
         * siblings of `entityKeys`. Each holds the 16-hex key (see
         * Common/Utils/Telemetry/EntityKey) of the row's entity of that type,
         * or '' when the resource carries no such entity (non-Nullable String,
         * so old rows read the type default ''). Unlike the array column, a
         * scalar equality predicate is usable as an MV/sort key and gets a
         * cheaper bloom-filter probe; only the high-traffic keys
         * (service/host/k8s.pod) carry skip indexes. Stamped at ingest by the
         * same extractor that fills `entityKeys`; never part of identity.
         */
        const scalarEntityKeyColumns = [
            {
                key: "serviceEntityKey",
                title: "Service Entity Key",
                indexName: "idx_service_entity_key",
            },
            {
                key: "hostEntityKey",
                title: "Host Entity Key",
                indexName: "idx_host_entity_key",
            },
            {
                key: "k8sPodEntityKey",
                title: "Kubernetes Pod Entity Key",
                indexName: "idx_k8s_pod_entity_key",
            },
            { key: "k8sNodeEntityKey", title: "Kubernetes Node Entity Key" },
            { key: "k8sClusterEntityKey", title: "Kubernetes Cluster Entity Key" },
            { key: "containerEntityKey", title: "Container Entity Key" },
        ].map((def) => {
            return new AnalyticsTableColumn({
                key: def.key,
                title: def.title,
                description: "Scalar entity key for this entity type (see entityKeys); '' when the resource has no entity of this type.",
                required: true,
                defaultValue: "",
                type: TableColumnType.Text,
                codec: { codec: "ZSTD", level: 1 },
                skipIndex: def.indexName
                    ? {
                        name: def.indexName,
                        type: SkipIndexType.BloomFilter,
                        params: [0.01],
                        granularity: 1,
                    }
                    : undefined,
                accessControl: entityKeysColumn.accessControl,
            });
        });
        const retentionDateColumn = new AnalyticsTableColumn({
            key: "retentionDate",
            codec: [{ codec: "DoubleDelta" }, { codec: "ZSTD", level: 1 }],
            title: "Retention Date",
            description: "Date after which this row is eligible for TTL deletion, computed at ingest time as time + service.retainTelemetryDataForDays",
            required: true,
            type: TableColumnType.Date,
            defaultValue: undefined,
        });
        super({
            tableName: AnalyticsTableName.ProfileSample,
            tableEngine: AnalyticsTableEngine.MergeTree,
            singularName: "ProfileSample",
            pluralName: "ProfileSamples",
            crudApiPath: new Route("/profile-sample"),
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceProfiles,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceProfiles,
                ],
                update: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.EditTelemetryServiceProfiles,
                ],
                delete: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.DeleteTelemetryServiceProfiles,
                ],
            },
            tableColumns: [
                projectIdColumn,
                primaryEntityIdColumn,
                primaryEntityTypeColumn,
                profileIdColumn,
                traceIdColumn,
                spanIdColumn,
                timeColumn,
                timeUnixNanoColumn,
                stacktraceColumn,
                stacktraceHashColumn,
                frameTypesColumn,
                valueColumn,
                profileTypeColumn,
                labelsColumn,
                entityKeysColumn,
                ...scalarEntityKeyColumns,
                retentionDateColumn,
            ],
            sortKeys: [
                "projectId",
                "time",
                "primaryEntityId",
                "profileType",
                "stacktraceHash",
            ],
            primaryKeys: [
                "projectId",
                "time",
                "primaryEntityId",
                "profileType",
                "stacktraceHash",
            ],
            partitionKey: "toYYYYMMDD(time)",
            tableSettings: "ttl_only_drop_parts = 1, non_replicated_deduplication_window = 10000",
            ttlExpression: "retentionDate DELETE",
            defaultSortColumn: "time",
        });
    }
    get projectId() {
        return this.getColumnValue("projectId");
    }
    set projectId(v) {
        this.setColumnValue("projectId", v);
    }
    get primaryEntityId() {
        return this.getColumnValue("primaryEntityId");
    }
    set primaryEntityId(v) {
        this.setColumnValue("primaryEntityId", v);
    }
    get primaryEntityType() {
        return this.getColumnValue("primaryEntityType");
    }
    set primaryEntityType(v) {
        this.setColumnValue("primaryEntityType", v);
    }
    get profileId() {
        return this.getColumnValue("profileId");
    }
    set profileId(v) {
        this.setColumnValue("profileId", v);
    }
    get traceId() {
        return this.getColumnValue("traceId");
    }
    set traceId(v) {
        this.setColumnValue("traceId", v);
    }
    get spanId() {
        return this.getColumnValue("spanId");
    }
    set spanId(v) {
        this.setColumnValue("spanId", v);
    }
    get time() {
        return this.getColumnValue("time");
    }
    set time(v) {
        this.setColumnValue("time", v);
    }
    get timeUnixNano() {
        return this.getColumnValue("timeUnixNano");
    }
    set timeUnixNano(v) {
        this.setColumnValue("timeUnixNano", v);
    }
    get stacktrace() {
        return this.getColumnValue("stacktrace");
    }
    set stacktrace(v) {
        this.setColumnValue("stacktrace", v);
    }
    get stacktraceHash() {
        return this.getColumnValue("stacktraceHash");
    }
    set stacktraceHash(v) {
        this.setColumnValue("stacktraceHash", v);
    }
    get frameTypes() {
        return this.getColumnValue("frameTypes");
    }
    set frameTypes(v) {
        this.setColumnValue("frameTypes", v);
    }
    get value() {
        return this.getColumnValue("value");
    }
    set value(v) {
        this.setColumnValue("value", v);
    }
    get profileType() {
        return this.getColumnValue("profileType");
    }
    set profileType(v) {
        this.setColumnValue("profileType", v);
    }
    get labels() {
        return this.getColumnValue("labels");
    }
    set labels(v) {
        this.setColumnValue("labels", v);
    }
    get entityKeys() {
        return this.getColumnValue("entityKeys");
    }
    set entityKeys(v) {
        this.setColumnValue("entityKeys", v);
    }
    get retentionDate() {
        return this.getColumnValue("retentionDate");
    }
    set retentionDate(v) {
        this.setColumnValue("retentionDate", v);
    }
};
ProfileSample = __decorate([
    OperationalResource(),
    OwnedThrough("primaryEntityId", Service, { includeProjectScope: true }),
    __metadata("design:paramtypes", [])
], ProfileSample);
export default ProfileSample;
//# sourceMappingURL=ProfileSample.js.map