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";
export var AggregationTemporality;
(function (AggregationTemporality) {
    AggregationTemporality["Delta"] = "Delta";
    AggregationTemporality["Cumulative"] = "Cumulative";
})(AggregationTemporality || (AggregationTemporality = {}));
export var MetricPointType;
(function (MetricPointType) {
    MetricPointType["Sum"] = "Sum";
    MetricPointType["Gauge"] = "Gauge";
    MetricPointType["Histogram"] = "Histogram";
    MetricPointType["ExponentialHistogram"] = "ExponentialHistogram";
    MetricPointType["Summary"] = "Summary";
})(MetricPointType || (MetricPointType = {}));
let Metric = class Metric 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.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        // this can also be the monitor id or the telemetry service id.
        const primaryEntityIdColumn = new AnalyticsTableColumn({
            key: "primaryEntityId",
            title: "Service ID",
            description: "ID of the Service which created the Metric",
            required: true,
            type: TableColumnType.ObjectID,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        // this can also be the monitor id or the telemetry service id.
        const primaryEntityTypeColumn = new AnalyticsTableColumn({
            key: "primaryEntityType",
            isLowCardinality: true,
            title: "Service Type",
            description: "Type of the service that this telemetry belongs to",
            required: false,
            type: TableColumnType.Text,
            skipIndex: {
                name: "idx_service_type",
                type: SkipIndexType.Set,
                params: [5],
                granularity: 4,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        // add name and description
        const nameColumn = new AnalyticsTableColumn({
            key: "name",
            codec: { codec: "ZSTD", level: 1 },
            title: "Name",
            description: "Name of the Metric",
            required: true,
            type: TableColumnType.Text,
            skipIndex: {
                name: "idx_name",
                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.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const aggregationTemporalityColumn = new AnalyticsTableColumn({
            key: "aggregationTemporality",
            // Enum-shaped (Delta / Cumulative / Unspecified) — dictionary-encode.
            isLowCardinality: true,
            title: "Aggregation Temporality",
            description: "Aggregation Temporality of this Metric",
            required: false,
            type: TableColumnType.Text,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const metricPointTypeColumn = new AnalyticsTableColumn({
            key: "metricPointType",
            isLowCardinality: true,
            title: "Metric Point Type",
            description: "Metric Point Type of this Metric",
            required: false,
            type: TableColumnType.Text,
            skipIndex: {
                name: "idx_metric_point_type",
                type: SkipIndexType.Set,
                params: [5],
                granularity: 4,
            },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        // this is end time.
        const timeColumn = new AnalyticsTableColumn({
            key: "time",
            codec: [{ codec: "DoubleDelta" }, { codec: "ZSTD", level: 1 }],
            title: "Time",
            description: "When did the Metric happen?",
            required: true,
            type: TableColumnType.DateTime64,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const startTimeColumn = new AnalyticsTableColumn({
            key: "startTime",
            codec: { codec: "ZSTD", level: 1 },
            title: "Start Time",
            description: "When did the Metric happen?",
            required: false,
            type: TableColumnType.DateTime64,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        // end time.
        const timeUnixNanoColumn = new AnalyticsTableColumn({
            key: "timeUnixNano",
            codec: [{ codec: "DoubleDelta" }, { codec: "ZSTD", level: 1 }],
            title: "Time (in Unix Nano)",
            description: "When did the Metric happen?",
            required: true,
            type: TableColumnType.UInt64,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const startTimeUnixNanoColumn = new AnalyticsTableColumn({
            key: "startTimeUnixNano",
            codec: [{ codec: "DoubleDelta" }, { codec: "ZSTD", level: 1 }],
            title: "Start Time (in Unix Nano)",
            description: "When did the Metric happen?",
            required: false,
            type: TableColumnType.UInt64,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const attributesColumn = new AnalyticsTableColumn({
            key: "attributes",
            codec: { codec: "ZSTD", level: 3 },
            title: "Attributes",
            description: "Attributes",
            required: true,
            type: TableColumnType.MapStringString,
            defaultValue: {},
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                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.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                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 (the per-host
         * minute rollup `MetricItemAggMV1mByHostV2` groups by `hostEntityKey`)
         * 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 attributeKeysColumn = new AnalyticsTableColumn({
            key: "attributeKeys",
            codec: { codec: "ZSTD", level: 3 },
            title: "Attribute Keys",
            description: "Attribute keys extracted from attributes",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayText,
            skipIndex: {
                name: "idx_attribute_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.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const isMonotonicColumn = new AnalyticsTableColumn({
            key: "isMonotonic",
            title: "Is Monotonic",
            description: "Is Monotonic",
            required: false,
            type: TableColumnType.Boolean,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const countColumn = new AnalyticsTableColumn({
            key: "count",
            codec: { codec: "ZSTD", level: 1 },
            title: "Count",
            description: "Count",
            required: false,
            type: TableColumnType.BigNumber,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const sumColumn = new AnalyticsTableColumn({
            key: "sum",
            codec: [{ codec: "Gorilla" }, { codec: "ZSTD", level: 1 }],
            title: "Sum",
            description: "Sum",
            required: false,
            type: TableColumnType.Decimal,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const valueColumn = new AnalyticsTableColumn({
            key: "value",
            codec: [{ codec: "Gorilla" }, { codec: "ZSTD", level: 1 }],
            title: "Value",
            description: "Value",
            required: false,
            type: TableColumnType.Decimal,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const minColumn = new AnalyticsTableColumn({
            key: "min",
            codec: [{ codec: "Gorilla" }, { codec: "ZSTD", level: 1 }],
            title: "Min",
            description: "Min",
            required: false,
            type: TableColumnType.Decimal,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const maxColumn = new AnalyticsTableColumn({
            key: "max",
            codec: [{ codec: "Gorilla" }, { codec: "ZSTD", level: 1 }],
            title: "Max",
            description: "Max",
            required: false,
            type: TableColumnType.Decimal,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const bucketCountsColumn = new AnalyticsTableColumn({
            key: "bucketCounts",
            codec: { codec: "ZSTD", level: 1 },
            title: "Bucket Counts",
            description: "Bucket Counts",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayBigNumber,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const explicitBoundsColumn = new AnalyticsTableColumn({
            key: "explicitBounds",
            codec: { codec: "ZSTD", level: 1 },
            title: "Explicit Bounds",
            description: "Upper bounds (exclusive of the +inf overflow bucket) for each explicit-bucket histogram bucket. Stored as Float64 so sub-integer boundaries (e.g. 0.005, 0.01) survive ingest — the previous Array(Int64) representation silently truncated those to 0.",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayDecimal,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        /*
         * --- ExponentialHistogram-only columns ----------------------------------
         * These are populated only when metricPointType = ExponentialHistogram.
         * For other metric types they are left at their defaults (0 / []).
         */
        const scaleColumn = new AnalyticsTableColumn({
            key: "scale",
            codec: { codec: "ZSTD", level: 1 },
            title: "Scale",
            description: "ExponentialHistogram resolution. base = 2^(2^-scale); bucket index `i` covers (base^i, base^(i+1)].",
            required: false,
            type: TableColumnType.Number,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const zeroCountColumn = new AnalyticsTableColumn({
            key: "zeroCount",
            codec: { codec: "ZSTD", level: 1 },
            title: "Zero Count",
            description: "ExponentialHistogram count of values within the zero region (|v| <= zeroThreshold).",
            required: false,
            type: TableColumnType.BigNumber,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const positiveOffsetColumn = new AnalyticsTableColumn({
            key: "positiveOffset",
            codec: { codec: "ZSTD", level: 1 },
            title: "Positive Bucket Offset",
            description: "Bucket index of the first entry in positiveBucketCounts (ExponentialHistogram).",
            required: false,
            type: TableColumnType.Number,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const positiveBucketCountsColumn = new AnalyticsTableColumn({
            key: "positiveBucketCounts",
            codec: { codec: "ZSTD", level: 1 },
            title: "Positive Bucket Counts",
            description: "Counts for the positive range of an ExponentialHistogram, indexed from positiveOffset.",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayBigNumber,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const negativeOffsetColumn = new AnalyticsTableColumn({
            key: "negativeOffset",
            codec: { codec: "ZSTD", level: 1 },
            title: "Negative Bucket Offset",
            description: "Bucket index of the first entry in negativeBucketCounts (ExponentialHistogram).",
            required: false,
            type: TableColumnType.Number,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const negativeBucketCountsColumn = new AnalyticsTableColumn({
            key: "negativeBucketCounts",
            codec: { codec: "ZSTD", level: 1 },
            title: "Negative Bucket Counts",
            description: "Counts for the negative range of an ExponentialHistogram, indexed from negativeOffset.",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayBigNumber,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        /*
         * --- Summary-only columns -----------------------------------------------
         * Populated only when metricPointType = Summary. Two parallel arrays
         * keyed by index (mirrors the bucketCounts/explicitBounds convention):
         *   summaryQuantiles[i] in [0,1], summaryValues[i] is value at that quantile.
         */
        const summaryQuantilesColumn = new AnalyticsTableColumn({
            key: "summaryQuantiles",
            codec: { codec: "ZSTD", level: 1 },
            title: "Summary Quantiles",
            description: "Quantile percentages in [0,1] for a Summary metric (parallel to summaryValues).",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayDecimal,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const summaryValuesColumn = new AnalyticsTableColumn({
            key: "summaryValues",
            codec: { codec: "ZSTD", level: 1 },
            title: "Summary Values",
            description: "Values corresponding to each quantile in summaryQuantiles for a Summary metric.",
            required: true,
            defaultValue: [],
            type: TableColumnType.ArrayDecimal,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const traceIdColumn = new AnalyticsTableColumn({
            key: "traceId",
            codec: { codec: "ZSTD", level: 1 },
            title: "Trace ID",
            description: "Trace ID from an exemplar associated with this metric data point",
            required: false,
            type: TableColumnType.Text,
            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.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        const spanIdColumn = new AnalyticsTableColumn({
            key: "spanId",
            codec: { codec: "ZSTD", level: 1 },
            title: "Span ID",
            description: "Span ID from an exemplar associated with this metric data point",
            required: false,
            type: TableColumnType.Text,
            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.ReadTelemetryServiceLog,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceLog,
                ],
                update: [],
            },
        });
        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.Metric,
            tableEngine: AnalyticsTableEngine.MergeTree,
            singularName: "Metric",
            pluralName: "Metrics",
            crudApiPath: new Route("/metrics"),
            enableDocumentation: true,
            tableDescription: "OpenTelemetry metric data points. Query and aggregate time-series telemetry for dashboards, alerts, and analysis.",
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.TelemetryViewer,
                    Permission.ReadTelemetryServiceTraces,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.CreateTelemetryServiceTraces,
                ],
                update: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.EditTelemetryServiceTraces,
                ],
                delete: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.TelemetryAdmin,
                    Permission.TelemetryMember,
                    Permission.DeleteTelemetryServiceTraces,
                ],
            },
            tableColumns: [
                projectIdColumn,
                primaryEntityIdColumn,
                primaryEntityTypeColumn,
                nameColumn,
                aggregationTemporalityColumn,
                metricPointTypeColumn,
                timeColumn,
                startTimeColumn,
                timeUnixNanoColumn,
                startTimeUnixNanoColumn,
                attributesColumn,
                attributeKeysColumn,
                entityKeysColumn,
                ...scalarEntityKeyColumns,
                isMonotonicColumn,
                countColumn,
                sumColumn,
                valueColumn,
                minColumn,
                maxColumn,
                bucketCountsColumn,
                explicitBoundsColumn,
                scaleColumn,
                zeroCountColumn,
                positiveOffsetColumn,
                positiveBucketCountsColumn,
                negativeOffsetColumn,
                negativeBucketCountsColumn,
                summaryQuantilesColumn,
                summaryValuesColumn,
                traceIdColumn,
                spanIdColumn,
                retentionDateColumn,
            ],
            projections: [],
            sortKeys: ["projectId", "name", "primaryEntityId", "time"],
            primaryKeys: ["projectId", "name", "primaryEntityId", "time"],
            partitionKey: "toYYYYMMDD(time)",
            tableSettings: "ttl_only_drop_parts = 1, non_replicated_deduplication_window = 10000",
            ttlExpression: "retentionDate DELETE",
            /*
             * `time` is the 4th column of the Metric sort key (after
             * projectId + name + primaryEntityId). A list query that filters
             * by name (the typical "metric detail" drilldown) can still
             * stream from the index when sorting by `time DESC`. With
             * no name filter the sort is less efficient but still far
             * better than the legacy `createdAt DESC` fallback, which
             * isn't in the sort key at all.
             */
            defaultSortColumn: "time",
        });
    }
    get projectId() {
        return this.getColumnValue("projectId");
    }
    set projectId(v) {
        this.setColumnValue("projectId", v);
    }
    get primaryEntityId() {
        return this.getColumnValue("primaryEntityId");
    }
    get primaryEntityType() {
        return this.getColumnValue("primaryEntityType");
    }
    get name() {
        return this.getColumnValue("name");
    }
    set name(v) {
        this.setColumnValue("name", v);
    }
    get aggregationTemporality() {
        return this.getColumnValue("aggregationTemporality");
    }
    set aggregationTemporality(v) {
        this.setColumnValue("aggregationTemporality", v);
    }
    get metricPointType() {
        return this.getColumnValue("metricPointType");
    }
    set metricPointType(v) {
        this.setColumnValue("metricPointType", v);
    }
    get isMonotonic() {
        return this.getColumnValue("isMonotonic");
    }
    set isMonotonic(v) {
        this.setColumnValue("isMonotonic", v);
    }
    set primaryEntityId(v) {
        this.setColumnValue("primaryEntityId", v);
    }
    set primaryEntityType(v) {
        this.setColumnValue("primaryEntityType", v);
    }
    get time() {
        return this.getColumnValue("time");
    }
    set time(v) {
        this.setColumnValue("time", v);
    }
    get attributes() {
        return this.getColumnValue("attributes");
    }
    set attributes(v) {
        this.setColumnValue("attributes", v);
    }
    get attributeKeys() {
        return this.getColumnValue("attributeKeys");
    }
    set attributeKeys(v) {
        this.setColumnValue("attributeKeys", v);
    }
    get entityKeys() {
        return this.getColumnValue("entityKeys");
    }
    set entityKeys(v) {
        this.setColumnValue("entityKeys", v);
    }
    get startTime() {
        return this.getColumnValue("startTime");
    }
    set startTime(v) {
        this.setColumnValue("startTime", v);
    }
    get startTimeUnixNano() {
        return this.getColumnValue("startTimeUnixNano");
    }
    set startTimeUnixNano(v) {
        this.setColumnValue("startTimeUnixNano", v);
    }
    get timeUnixNano() {
        return this.getColumnValue("timeUnixNano");
    }
    set timeUnixNano(v) {
        this.setColumnValue("timeUnixNano", v);
    }
    get count() {
        return this.getColumnValue("count");
    }
    set count(v) {
        this.setColumnValue("count", v);
    }
    get sum() {
        return this.getColumnValue("sum");
    }
    set sum(v) {
        this.setColumnValue("sum", v);
    }
    get value() {
        return this.getColumnValue("value");
    }
    set value(v) {
        this.setColumnValue("value", v);
    }
    get min() {
        return this.getColumnValue("min");
    }
    set min(v) {
        this.setColumnValue("min", v);
    }
    get max() {
        return this.getColumnValue("max");
    }
    set max(v) {
        this.setColumnValue("max", v);
    }
    get bucketCounts() {
        return this.getColumnValue("bucketCounts");
    }
    set bucketCounts(v) {
        this.setColumnValue("bucketCounts", v);
    }
    get explicitBounds() {
        return this.getColumnValue("explicitBounds");
    }
    set explicitBounds(v) {
        this.setColumnValue("explicitBounds", 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 retentionDate() {
        return this.getColumnValue("retentionDate");
    }
    set retentionDate(v) {
        this.setColumnValue("retentionDate", v);
    }
    get scale() {
        return this.getColumnValue("scale");
    }
    set scale(v) {
        this.setColumnValue("scale", v);
    }
    get zeroCount() {
        return this.getColumnValue("zeroCount");
    }
    set zeroCount(v) {
        this.setColumnValue("zeroCount", v);
    }
    get positiveOffset() {
        return this.getColumnValue("positiveOffset");
    }
    set positiveOffset(v) {
        this.setColumnValue("positiveOffset", v);
    }
    get positiveBucketCounts() {
        return this.getColumnValue("positiveBucketCounts");
    }
    set positiveBucketCounts(v) {
        this.setColumnValue("positiveBucketCounts", v);
    }
    get negativeOffset() {
        return this.getColumnValue("negativeOffset");
    }
    set negativeOffset(v) {
        this.setColumnValue("negativeOffset", v);
    }
    get negativeBucketCounts() {
        return this.getColumnValue("negativeBucketCounts");
    }
    set negativeBucketCounts(v) {
        this.setColumnValue("negativeBucketCounts", v);
    }
    get summaryQuantiles() {
        return this.getColumnValue("summaryQuantiles");
    }
    set summaryQuantiles(v) {
        this.setColumnValue("summaryQuantiles", v);
    }
    get summaryValues() {
        return this.getColumnValue("summaryValues");
    }
    set summaryValues(v) {
        this.setColumnValue("summaryValues", v);
    }
};
Metric = __decorate([
    OperationalResource(),
    OwnedThrough("primaryEntityId", Service, { includeProjectScope: true }),
    __metadata("design:paramtypes", [])
], Metric);
export default Metric;
//# sourceMappingURL=Metric.js.map