UNPKG

@northflank/cli

Version:

Provides a command-line interface to the Northflank platform.

1 lines 11.5 kB
const a13U=a13E;(function(m,E){const M=a13E,h=m();while(!![]){try{const I=-parseInt(M(0x204))/0x1*(parseInt(M(0x220))/0x2)+parseInt(M(0x20a))/0x3*(-parseInt(M(0x21a))/0x4)+-parseInt(M(0x216))/0x5+-parseInt(M(0x1ac))/0x6*(parseInt(M(0x1d2))/0x7)+parseInt(M(0x1f3))/0x8*(parseInt(M(0x1e8))/0x9)+parseInt(M(0x1a7))/0xa*(-parseInt(M(0x1b4))/0xb)+-parseInt(M(0x1eb))/0xc*(-parseInt(M(0x21b))/0xd);if(I===E)break;else h['push'](h['shift']());}catch(T){h['push'](h['shift']());}}}(a13m,0x36ad8));import{ApiClient,MetricType}from'@northflank/js-client';import{assertContextExisting,customUserAgent,error,getCommand,parseDateInput,tsHint,warning}from'../utils.js';function a13m(){const m9=['20PmyQkQ','inquirerHelper','values','split','rows','2346402mAtPrl','min','yml','askForProjectContext','valueOf','--build\x20--buildId\x20[buildId]','printMetricsTable','error','98989miUCjA','getCurrentServiceName','option','Job\x20run\x20id,\x20example:\x20162b1977-6636-4000-929b-cc265b862ff0','value','name','Metrics\x20overview','\x20of\x20','action','choices','containerId','addonId','--container\x20--containerId\x20[NAME]','deploymentId','assign','log','runId','bold','forEach','toFixed','apiContext','org','jobId','Id\x20[NAME]','metrics','service','printInitInfo','-t,\x20--metricTypes\x20<metricTypes...>','stringify','--run\x20--runId\x20[runId]','7UOlvdm','Error\x20while\x20fetching\x20metrics\x20entries:\x20','\x20seconds','metricsApiClient',',\x20to:\x20','charAt','getTokenScope','json','unshift',',\x20metric\x20types:\x20','stdout','max','\x20to\x20get\x20logs\x20from','metricsSingle','Deployment\x20id,\x20example:\x20my-service-54785f4','--endTime\x20<timestamp>','apiClient','getMetricsCommand','Get\x20metrics\x20after\x20this\x20timestamp,\x20','Length\x20of\x20timespan\x20in\x20seconds.\x20Only\x20valid\x20if\x20not\x20both,\x20startTime\x20and\x20endTime\x20are\x20set','job','printMetricsGraph','4077kUunOr','metadata','askForJob','1766148TmfHCd','getPaddingDataEnd','length','handleError','Get\x20metrics\x20before\x20this\x20timestamp,\x20','time','slice','askForTeam','7544StcsHK','-o,\x20--output\x20[output]','Only\x20two\x20of\x20\x27startTime\x27,\x20\x27endTime\x27\x20and\x20\x27duration\x27\x20can\x20be\x20set.','noDefaults','printMetricsSingle','getTime','clear','toISOString','Project\x20for\x20logs','--team\x20--teamId\x20[TEAMID]','all\x20containers','askForProject','message','format','N/A',',\x20duration:\x20','build-','3tyznqX','pct','description','toTimeString','askForJobRun','map','71415uilOSw','metricUnit','alias','addOption','data','endTime','yaml','metricId','keys','details','Fetching\x20data..','askForService','870360hLnxKD','Team\x20id','exit','getStandardMetricsCommand','60RwBREd','104oWonxU','conflicts','argParser','flat','startTime','293626eixTNf','contextProvider','\x20--','addon','metricsRange','refreshInterval','columns','Metrics\x20for\x20',',\x20volume:\x20','askForAddon'];a13m=function(){return m9;};return a13m();}import{InquirerHelper}from'../inquirer-helper.js';import{Option}from'commander';import{downSampleData,getAsciiChart}from'../formatting/terminal-chart.js';function a13E(m,E){const h=a13m();return a13E=function(I,T){I=I-0x1a6;let e=h[I];return e;},a13E(m,E);}import{printAsTable,printResponse}from'../formatting/console-format-helpers.js';import a13h from'chalk';export class CliMetrics{[a13U(0x1c8)];[a13U(0x1e2)];[a13U(0x1d5)];[a13U(0x1a8)];['refreshInterval']=0x2710;['getStandardMetricsCommand']=(m,E)=>{const C=a13U,h=getCommand(!![])[C(0x1b9)]((E?C(0x203):'')+'metrics')[C(0x20c)]((E?C(0x203):'')+'metric')[C(0x206)]('Get\x20metrics\x20for\x20the\x20specified\x20'+m)['option']('--project\x20--projectId\x20[NAME]',C(0x1fb))[C(0x1b6)]('--'+m+C(0x222)+m+C(0x1cb),m[C(0x1d7)](0x0)['toUpperCase']()+m[C(0x1f1)](0x1)+C(0x1de))['option'](C(0x1c0),'Container\x20to\x20exec\x20into\x20(logs\x20from\x20all\x20containers\x20will\x20be\x20shown\x20if\x20not\x20specified)')[C(0x1b6)]('--startTime\x20<timestamp>',C(0x1e4)+tsHint,parseDateInput)['option'](C(0x1e1),C(0x1ef)+tsHint,parseDateInput)[C(0x1b6)]('--duration\x20[duration]',C(0x1e5))[C(0x20d)](new Option(C(0x1cf),'Which\x20metric\x20type\x20to\x20fetch')[C(0x1bd)](Object['values'](MetricType)))['addOption'](new Option('--timestamp\x20[timestamp]','Get\x20metrics\x20at\x20this\x20exact\x20timestamp,\x20if\x20no\x20timestamp\x20set\x20most\x20recent\x20time\x20is\x20used.\x20'+tsHint)[C(0x21d)](parseDateInput)[C(0x21c)]([C(0x21f),C(0x20f)]))[C(0x1b6)]('--noDefaults','Don\x27t\x20use\x20context\x20default\x20values,\x20explicitly\x20use\x20options\x20or\x20ask.',![])[C(0x20d)](new Option(C(0x1f4),'Output\x20formatting.\x20Will\x20use\x20advanced\x20formatting\x20by\x20default.')[C(0x1bd)](Object[C(0x1a9)]([C(0x200),C(0x1d9),C(0x210)])));if(E)h[C(0x1b6)](C(0x1b1),'Build\x20to\x20get\x20logs\x20from');if(m===C(0x1e6))h[C(0x1b6)](C(0x1d1),C(0x1b7));if(m===C(0x1cd))h[C(0x1b6)]('--deployment\x20--deploymentId\x20[deploymentId]',C(0x1e0));return this[C(0x1e2)][C(0x221)][C(0x1d8)]()===C(0x1c9)&&h[C(0x1b6)](C(0x1fc),C(0x217)),h;};constructor(m,E){const Z=a13U;this[Z(0x1c8)]=m,this[Z(0x1e2)]=new ApiClient(m,{'throwErrorOnHttpErrorCode':!![],'customUserAgent':customUserAgent,'agent':E}),this[Z(0x1d5)]=this[Z(0x1e2)],this['inquirerHelper']=new InquirerHelper(this[Z(0x1e2)]);}[a13U(0x1e3)](m,E=![]){const y=a13U,h=async(g,J,L)=>{const i=a13E,P=L[i(0x1f6)],{apiContext:X,inquirerHelper:W}=this;switch(m){case i(0x1cd):{const K=P?undefined:X[i(0x1b5)]();return L['serviceId']||K||await W[i(0x215)](g,J)();}case'job':{const z=P?undefined:X['getCurrentServiceName']();return L[i(0x1ca)]||z||await W[i(0x1ea)](g,J)();}case i(0x223):{const S=P?undefined:X[i(0x1b5)]();return L[i(0x1bf)]||S||await W[i(0x1a6)](g,J)();}}},I=async(g,J,L,P)=>{const V=a13E;if(E)return P['buildId']||await this[V(0x1a8)]['askForBuild'](g,m===V(0x1cd)?L:undefined,m===V(0x1e6)?L:undefined,!![],J)();return undefined;},T=async(g,J,L,P)=>{const G=a13E;if(!E&&P[G(0x1be)]!==undefined){if(P['containerId']!==!![])return P[G(0x1be)];return await this[G(0x1a8)]['askForContainer'](g,m===G(0x1cd)?L:undefined,m==='job'?L:undefined,!![],J)();}return undefined;},e=async(g,J,L,P)=>{const l=a13E;if(m===l(0x1e6))return P[l(0x1c4)]||await this['inquirerHelper'][l(0x208)](L,g,!![],J)();return undefined;},o=async(g,J,L,P)=>{const s=a13E;if(m==='service'){if(P[s(0x1c1)]!==!![])return P[s(0x1c1)];return P[s(0x1c1)];}return undefined;};return this[y(0x219)](m,E)[y(0x1bc)](async g=>{const u=y,{noDefaults:J,projectId:L,teamId:P,duration:X,timestamp:W,output:K,startTime:z,endTime:S,metricTypes:H,quiet:r}=g;assertContextExisting(this['apiClient']);if(z&&S&&X)throw new Error(u(0x1f5));const {apiContext:F,inquirerHelper:t,metricsApiClient:Y}=this,N=J?undefined:F['getCurrentProjectName'](),{projectId:w,teamId:b}=await this['askForProjectContext'](F,t,L,P,N),n=await h(w,b,g),Q=await I(w,b,n,g),c=await e(w,b,n,g),O=await o(w,b,n,g),B=await T(w,b,n,g),q={'teamId':b,'projectId':w,'entityId':n},a={'containerName':B,'startTime':z,'endTime':S,'duration':X,'timestamp':W,'metricTypes':H,'runId':c,'buildId':Q,'deploymentId':O,'isBuild':E??![]},R=!(z||S||X);if(!r&&K!==u(0x210)&&K!==u(0x1ae)&&K!=='json')this[u(0x1ce)](m,n,w,a,r);if(R){if(K!==undefined){const x=await Y['metrics'][u(0x1df)](q,a,m);this[u(0x1ee)](x),printResponse(K,x['data']);}else[...Array(process[u(0x1dc)]['rows']-0x1)][u(0x1c6)]((D,f)=>f===0x0?console[u(0x1c3)](u(0x214)):console[u(0x1c3)]()),await this[u(0x1b2)](q,a,m)(),setInterval(this[u(0x1b2)](q,a,m),this[u(0x225)]),await new Promise(D=>setTimeout(D,this['refreshInterval']*0x64));}else{const D=await Y[u(0x1cc)][u(0x224)](q,a,m);this[u(0x1ee)](D),K!==undefined?printResponse(K,D[u(0x20e)]):this[u(0x1e7)](z,S??new Date())(D[u(0x20e)]);}process[u(0x218)]();});}[a13U(0x1f7)](m){const p=a13U,E=(T,e)=>{const k=a13E;if(!e?.[k(0x1b8)])k(0x201);const o=T['metricUnit']===k(0x205)?'%':T[k(0x20b)];return''+Number(e?.[k(0x1b8)])[k(0x1c7)](0x3)+o;},h=T=>{const A=a13E;if(!T?.['ts'])A(0x201);return T['ts'][A(0x207)]()[A(0x1aa)]('\x20')[0x0];},I={};Object[p(0x212)](m)[p(0x1c6)](T=>{const j=p,{values:e,metricInfo:o}=m[T];return e[j(0x1c6)](g=>{const d=j,J=g[d(0x1e9)][d(0x1be)];Object[d(0x1c2)](I,{[J]:{...I?.[J],[d(0x1f0)]:h(g[d(0x20e)]?.[0x0]),'containerId':J,[o[d(0x211)]]:E(o,g[d(0x20e)]?.[0x0])}});});}),printAsTable(Object['values'](I),p(0x1ba));}['printMetricsGraph']=(m,E)=>{return h=>{const v=a13E,I=Object[v(0x212)](h)['flatMap'](T=>{const m0=v,{values:e,metricInfo:o}=h[T],{metricUnit:g,metricResolution:J}=o;return e[m0(0x209)](L=>{const m1=m0,{metadata:P,data:X}=L,W=E?E?.[m1(0x1f8)]()>new Date()[m1(0x1f8)]()?new Date():E:undefined,K=new Date(X?.[0x0]?.['ts']),z=new Date(X?.[X[m1(0x1ed)]-0x1]?.['ts']),S=this['getPaddingDataStart'](m,K,J),H=this[m1(0x1ec)](W,z,J),r=[...S,...X,...H],F=r[m1(0x209)](c=>[new Date(c['ts'])[m1(0x1b0)](),Number(c[m1(0x1b8)])])['filter'](c=>!Number['isNaN'](c[0x0])),t=Math[m1(0x1ad)](Math[m1(0x1dd)](process[m1(0x1dc)][m1(0x226)]-0xa,0xa),0x64),Y=Math[m1(0x1ad)](Math[m1(0x1dd)](process[m1(0x1dc)][m1(0x1ab)]-0x9,0xa),0xf),N=g===m1(0x205)?0x64:undefined,w=g===m1(0x205)?'%':g,b=downSampleData(F,t),n=b[m1(0x209)](c=>c[0x1]),Q={'min':0x0,'height':Y,'max':N,'unit':w,'startTs':m??K,'endTs':W??z};return{'dataSeries':n,'metadata':P,'chartOpts':Q,'metricInfo':o};});})[v(0x21e)]();if(I['length']===0x0)warning('No\x20metrics\x20found\x20for\x20this\x20query');else I[v(0x1c6)](T=>{const m2=v,{dataSeries:e,metadata:o,chartOpts:g,metricInfo:J}=T,{containerId:L,volumeId:P}=o,X=P?m2(0x228)+P:'';console[m2(0x1c3)](J[m2(0x211)]+'\x20for\x20container:\x20'+a13h['bold'](L)+X),console[m2(0x1c3)](getAsciiChart(e,g));});};};['getPaddingDataStart'](m,E,h){const m3=a13U,I=o=>new Date(o[m3(0x1f8)]()-T),T=h*0x3e8;if(!m)return[];if(!E)return[];if(I(E)['getTime']()<m[m3(0x1f8)]())return[];const e=[{'ts':I(E),'value':0x0}];while(I(e[e[m3(0x1ed)]-0x1]['ts'])[m3(0x1f8)]()<=m[m3(0x1f8)]()){e[m3(0x1da)]({'ts':I(e[e[m3(0x1ed)]-0x1]['ts']),'value':0x0});}return e;}['getPaddingDataEnd'](m,E,h){const m4=a13U,I=o=>new Date(o[m4(0x1f8)]()+T),T=h*0x3e8;if(!m)return[];if(!E)return[];if(I(E)[m4(0x1f8)]()>m[m4(0x1f8)]())return[];const e=[{'ts':I(E),'value':0x0}];while(I(e[e['length']-0x1]['ts'])[m4(0x1f8)]()<=m['getTime']()){e['push']({'ts':I(e[e['length']-0x1]['ts']),'value':0x0});}return e;}['printMetricsTable']=(m,E,h)=>async()=>{const m5=a13U;try{const I=await this[m5(0x1d5)][m5(0x1cc)][m5(0x1df)](m,E,h);console['clear']();if(I[m5(0x1b3)])error(m5(0x1d3)+I[m5(0x1b3)][m5(0x1ff)]);else this['printMetricsSingle'](I[m5(0x20e)]);}catch(T){console[m5(0x1f9)](),error(m5(0x1d3)+T[m5(0x1ff)]);}};[a13U(0x1ee)]=m=>{const m6=a13U;if(m[m6(0x1b3)]){const E=JSON[m6(0x1d0)](m['error'][m6(0x213)]);throw new Error('Error\x20while\x20fetching\x20metrics\x20entries:\x20'+m[m6(0x1b3)]['message']+'\x20'+E);}};[a13U(0x1ce)]=(m,E,h,I,T)=>{const m7=a13U;if(T===!![])return;const {metricTypes:e,endTime:o,startTime:g,duration:J,containerId:L}=I,P=g?',\x20from:\x20'+g['toISOString']():'',X=o?m7(0x1d6)+o[m7(0x1fa)]():'',W=J?m7(0x202)+J+m7(0x1d4):'',K=L?'container\x20'+a13h[m7(0x1c5)](L):m7(0x1fd),z=m+'\x20'+a13h[m7(0x1c5)](E)+'\x20in\x20project\x20'+a13h['bold'](h),S=''+P+X+W,H=e?m7(0x1db)+e?.['join'](','):'';console[m7(0x1c3)](m7(0x227)+K+m7(0x1bb)+z+H+S);};[a13U(0x1af)]=async(m,E,h,I,T)=>{const m8=a13U,e=m[m8(0x1d8)]()===m8(0x1c9)?I??await E[m8(0x1f2)]()():undefined,o=h||T||await E[m8(0x1fe)](e)();return{'teamId':e,'projectId':o};};}