
-- CLOUD-16405 Metric Meta | 대시보드 관련 메트릭 수정
-- 대시보드 관련 메트릭 추가 및 오타 수정
INSERT INTO public.metric_meta2 (id,meta_name,description,expr,resource_type,entity_type,groupby_keys,in_use,anomaly_score,message,created_date,modified_date) VALUES
     ('redis_connected_slave_lag_seconds','Redis Connected Slave Lag Seconds','Redis Connected Slave Lag Seconds','sum by (xm_clst_id, xm_namespace, xm_node_id, instance, slave_ip, slave_port) (rate(redis_connected_slave_lag_seconds[1m]))','Worker','Redis',NULL,true,true,'Redis Connected Slave Lag Seconds','2023-03-16 14:39:57.420','2023-03-16 14:39:57.420'),
     ('redis_connected_slave_offset_bytes','Redis Connected Slave Offset Bytes','Redis Connected Slave Offset Bytes','sum by (xm_clst_id, xm_namespace, xm_node_id, instance, slave_ip, slave_port) (rate(redis_connected_slave_offset_bytes[1m]))','Worker','Redis',NULL,true,true,'Redis Connected Slave Offset Bytes','2023-03-16 14:37:43.734','2023-03-16 14:38:22.164'),
     ('redis_connected_slaves','Redis Connected Slaves','Redis Connected Slaves','sum by (xm_clst_id, xm_namespace, xm_node_id, instance) (redis_connected_slaves)','Worker','Redis',NULL,true,true,'Redis Connected Slaves','2023-03-16 13:57:09.423','2023-03-16 13:59:50.746');
INSERT INTO public.metric_meta2 (id,meta_name,description,expr,resource_type,entity_type,groupby_keys,in_use,anomaly_score,message,created_date,modified_date) VALUES
     ('traefik_http_requests_bad_total_last_10m','Traefik HTTP Requests  Bad Total Last 10m','Number bad requests in 10 minutes','sum(increase(traefik_service_requests_total{code=~"4[0-9]{2}|5[0-9]{2}"}[10m]))','Request','Traefik','service',true,false,'CLST:{{$labels.xm_clst_id}} NS:{{$labels.xm_namespace}} POD:{{$labels.xm_pod_id}}  Trafik Bad Request Count (10m) :{{humanize $value}}|{threshold}.','2023-03-17 14:10:13.163','2023-03-17 14:10:13.163'),
     ('traefik_http_requests_bad_total_last_1h','Traefik HTTP Requests Bad Total Last 1h','Number bad requests in 1 hour','sum(increase(traefik_service_requests_total{code=~"4[0-9]{2}|5[0-9]{2}"}[1h]))','Request','Traefik','service',true,false,'CLST:{{$labels.xm_clst_id}} NS:{{$labels.xm_namespace}} POD:{{$labels.xm_pod_id}}  Trafik Bad Request Count (1h) :{{humanize $value}}|{threshold}.','2023-03-17 14:10:13.163','2023-03-17 14:10:13.163');
INSERT INTO public.metric_meta2 (id,meta_name,description,expr,resource_type,entity_type,groupby_keys,in_use,anomaly_score,message,created_date,modified_date) VALUES
     ('traefik_status_code_count','Traefik Status Code Count ','Traefik Status Code Count ','sum(increase(traefik_service_requests_total{protocol=~"http|https"}[10m])) by (code)','Request','Traefik','code',true,false,'None','2023-03-17 14:33:13.020','2023-03-17 14:33:13.020');
-- Auto-generated SQL script #202305081122
UPDATE public.metric_meta2
    SET meta_name='Traefik HTTP Requests 5xx Total Last 1h'
    WHERE id='traefik_http_requests_5xx_total_last_1h';

-- CLOUD-16467 Metric Meta | Secret 정보를 저장하는 Table 을 추가한다.
CREATE TABLE cmoa_secret_base    (
    kube_flatting_time         bigint       not null,
    cluster_id                 varchar(255) not null,
    kind                       varchar(30)  not null,
    metadata_uid               varchar(40)  not null,
    row_index                  integer      not null,
    metadata_name              text,
    kind_status                varchar(50),
    metadata_resourceversion   text,
    metadata_annotations       text,
    metadata_creationtimestamp varchar(25),
    metadata_labels            text,
    metadata_namespace         text,
    data                       text,
    type                       text,
    create_time                timestamp default now(),
    PRIMARY KEY (kube_flatting_time, cluster_id, kind, metadata_uid, row_index)
);

ALTER TABLE cmoa_pod_volume
    add spec_volumes_persistentvolumeclaim text;

-- CLOUD-16396 Setting>Deploy List 에서 scale, yaml 에 대한 권한 때문에 menu 초기화
INSERT INTO public.auth_resource3 (name, is_deleted, tenant_id) VALUES ('menu|Workloads|Deploy List|Scale', false, null);
INSERT INTO public.auth_resource3 (name, is_deleted, tenant_id) VALUES ('menu|Workloads|Deploy List|Yaml', false, null);
INSERT INTO public.auth_resource3 (name, is_deleted, tenant_id) VALUES ('menu|Workloads|Deploy List|List', false, null);

INSERT INTO public.menu_meta (id, description, icon, "position", url, auth_resource3_id, scope_level) VALUES (13, 'deployList(List)', NULL, 5, '', (select id from auth_resource3 where name='menu|Workloads|Deploy List|List'), 0);
INSERT INTO public.menu_meta (id, description, icon, "position", url, auth_resource3_id, scope_level) VALUES (14, 'deployList(Scale)', NULL, 6, '', (select id from auth_resource3 where name='menu|Workloads|Deploy List|Scale'), 0);
INSERT INTO public.menu_meta (id, description, icon, "position", url, auth_resource3_id, scope_level) VALUES (15, 'deployList(Yaml)', NULL, 7, '', (select id from auth_resource3 where name='menu|Workloads|Deploy List|Yaml'), 0);