Repository navigation
Expand file tree
/
Copy pathdevelopers.html
More file actions
562 lines (544 loc) · 35.3 KB
/
Copy pathdevelopers.html
File metadata and controls
562 lines (544 loc) · 35.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Code To Profile | Runtime Conditions</title>
<meta name="description" content="How application code turns into a Runtime Conditions profile across Go, Python, Java, and TypeScript." />
<link rel="canonical" href="https://runtimeconditions.io/developers.html" />
<meta property="og:type" content="website" />
<meta property="og:title" content="Code To Profile | Runtime Conditions" />
<meta property="og:description" content="How application code turns into a Runtime Conditions profile across Go, Python, Java, and TypeScript." />
<meta property="og:url" content="https://runtimeconditions.io/developers.html" />
<meta property="og:site_name" content="Runtime Conditions" />
<meta property="og:image" content="https://runtimeconditions.io/assets/social-card.jpg" />
<meta property="og:image:type" content="image/jpeg" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta property="og:image:alt" content="Runtime Conditions logo: declare what your app needs to run." />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="Code To Profile | Runtime Conditions" />
<meta name="twitter:description" content="How application code turns into a Runtime Conditions profile across Go, Python, Java, and TypeScript." />
<meta name="twitter:image" content="https://runtimeconditions.io/assets/social-card.jpg" />
<meta name="twitter:image:alt" content="Runtime Conditions logo: declare what your app needs to run." />
<link rel="icon" type="image/svg+xml" href="assets/runtime-conditions-icon.svg" />
<link rel="icon" type="image/png" sizes="32x32" href="assets/icon-32.png" />
<link rel="apple-touch-icon" href="assets/apple-touch-icon.png" />
<link rel="stylesheet" href="assets/styles.css" />
<script src="assets/theme.js"></script>
</head>
<body>
<header class="site-header">
<div class="header-inner">
<a class="brand" href="index.html"><img class="brand-logo" src="assets/runtime-conditions-logo.svg" width="165" height="56" alt="Runtime Conditions"></a>
<nav class="top-links" aria-label="Top links">
<a href="https://github.com/runtimeconditions/spec/blob/main/docs/sixth-draft.md" data-tip="Read the latest draft of the specification" target="_blank" rel="noopener noreferrer"><svg class="nav-icon" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5"/><path d="M9 13h6"/><path d="M9 17h6"/></svg><span>Current Draft</span></a>
<a href="https://github.com/runtimeconditions/rc-demos/blob/main/README.md" data-tip="Run Runtime Conditions end to end on your own machine" target="_blank" rel="noopener noreferrer"><svg class="nav-icon" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="10"/><polygon points="10 8 16 12 10 16 10 8"/></svg><span>Run Demo</span></a>
<a href="reference.html" data-tip="See where each part of this guide comes from in the source repositories"><svg class="nav-icon" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3 6l6-3 6 3 6-3v15l-6 3-6-3-6 3z"/><path d="M9 3v15"/><path d="M15 6v15"/></svg><span>Source Map</span></a>
<a href="https://extensions.runtimeconditions.io/" data-tip="Browse every extension and its Go, Python, TypeScript and Java packages" target="_blank" rel="noopener noreferrer"><svg class="nav-icon" viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M21 8l-9-5-9 5 9 5 9-5z"/><path d="M3 8v8l9 5 9-5V8"/><path d="M12 13v8"/></svg><span>Registry</span></a>
<a class="social-link social-github" href="https://github.com/runtimeconditions" data-tip="Browse the Runtime Conditions repositories on GitHub" target="_blank" rel="noopener noreferrer"><svg class="nav-icon" viewBox="0 0 24 24" width="18" height="18" fill="currentColor" aria-hidden="true" focusable="false"><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg><span class="visually-hidden">GitHub</span></a>
<a class="social-link social-slack" href="https://cloud-native.slack.com/archives/C0C0R4M65FZ" data-tip="Join the conversation on the CNCF Slack" target="_blank" rel="noopener noreferrer"><svg class="nav-icon" viewBox="0 0 24 24" width="18" height="18" fill="currentColor" aria-hidden="true" focusable="false"><path class="slack-red" d="M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313z"/><path class="slack-blue" d="M8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312z"/><path class="slack-green" d="M18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312z"/><path class="slack-yellow" d="M15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z"/></svg><span class="visually-hidden">Slack</span></a>
</nav>
</div>
</header>
<div class="guide-layout">
<aside class="sidebar" aria-label="Guide chapters">
<p class="sidebar-title">Reader Guide</p>
<ol class="chapter-list">
<li><a href="index.html"><span class="num">00</span><span>Start here</span></a></li>
<li><a href="concepts.html"><span class="num">01</span><span>Core concepts</span></a></li>
<li><a href="spec.html"><span class="num">02</span><span>Profile shape</span></a></li>
<li><a aria-current="page" href="developers.html"><span class="num">03</span><span>Code to profile</span></a></li>
<li><a href="extensions.html"><span class="num">04</span><span>Extensions</span></a></li>
<li><a href="cli.html"><span class="num">05</span><span>rc CLI</span></a></li>
<li><a href="platform.html"><span class="num">06</span><span>Adapters</span></a></li>
<li><a href="demo.html"><span class="num">07</span><span>Run the demo</span></a></li>
<li><a href="reference.html"><span class="num">08</span><span>Reference</span></a></li>
<li><a href="faq.html"><span class="num">09</span><span>FAQ</span></a></li>
</ol>
</aside>
<main class="content">
<p class="chapter-label">Chapter 3</p>
<h1 class="page-title">The profiler turns source declarations into profile YAML.</h1>
<p class="intro">
Declare what an app needs in the language it is written in, run the profiler, and get a profile. Pick your language.
</p>
<section class="section" id="declare">
<div class="tabs">
<div class="tab-list" role="tablist" aria-label="Language"><button type="button" role="tab" id="tab-button-go" aria-controls="tab-go" aria-selected="true">Go</button><button type="button" role="tab" id="tab-button-java" aria-controls="tab-java" aria-selected="false">Java</button><button type="button" role="tab" id="tab-button-python" aria-controls="tab-python" aria-selected="false">Python</button><button type="button" role="tab" id="tab-button-typescript" aria-controls="tab-typescript" aria-selected="false">TypeScript</button></div>
<div class="tab-panel" id="tab-go" role="tabpanel" aria-labelledby="tab-button-go">
<h3>1. Add the packages</h3>
<p class="short">Add the generated binding modules like any Go module. The Go profiler is built into <code>rc</code>.</p>
<p class="short">These two are the packages for Common Integrations and Env Configuration. Every extension has packages in all four languages: see the <a href="extensions.html#binding-packages">Binding packages</a> table.</p>
<div class="example">
<div class="example-title"><span>Install</span></div>
<pre><code>go get runtimeconditions.io/x/rc/common runtimeconditions.io/x/rc/env</code></pre>
</div>
<h3>2. Declare what the app needs</h3>
<p class="short">Each declaration is a call built from generated types, so the compiler checks every field. The calls do nothing when the app runs. The app below needs an HTTP API, with the environment variable that holds its URL, and a Redis cache, with two ways to find it.</p>
<div class="example">
<div class="example-title"><span>conditions.go</span></div>
<pre><code>package main
import (
"runtimeconditions.io/x/rc/common"
"runtimeconditions.io/x/rc/env"
)
func declaration() {
_ = common.Api(
common.Http{
Spec: &common.Spec{Format: common.FormatOpenapi, Uri: "catalog://api/default/todos-api"},
Operations: common.HttpOperations{
{Method: common.MethodGet, Path: "/todos/{id}"},
},
},
env.HttpConfiguration{
Env: env.HttpConfigurationEnv{
{Name: "TODOS_API_URL", Property: env.HttpConfigurationEnvPropertyBaseUrl},
},
},
)
_ = common.Cache(
common.KeyValue{Engine: &[]common.KeyValueEngine{common.KeyValueEngineRedis}[0]},
env.KeyValueConfiguration{
Alternatives: env.KeyValueConfigurationAlternatives{
{Env: env.KeyValueConfigurationAlternativesEnv{
{Name: "REDIS_URL", Property: env.KeyValueConfigurationAlternativesEnvPropertyUrl},
}},
{Env: env.KeyValueConfigurationAlternativesEnv{
{Name: "REDIS_HOST", Property: env.KeyValueConfigurationAlternativesEnvPropertyHostname},
{Name: "REDIS_PORT", Property: env.KeyValueConfigurationAlternativesEnvPropertyPort},
}},
},
},
)
}</code></pre>
</div>
<h3>3. Use the variables in normal code</h3>
<p class="short">The profile records the names <code>TODOS_API_URL</code> and <code>REDIS_URL</code>, not their values. The app reads them as it always did, and the platform supplies them later.</p>
<div class="example">
<div class="example-title"><span>main.go</span></div>
<pre><code>func checkTodosAPI(ctx context.Context) error {
baseURL := strings.TrimRight(os.Getenv("TODOS_API_URL"), "/")
if baseURL == "" {
return errors.New("TODOS_API_URL is not set")
}
request, err := http.NewRequestWithContext(ctx, http.MethodGet, baseURL+"/todos/1", nil)
if err != nil {
return err
}
response, err := http.DefaultClient.Do(request)
if err != nil {
return fmt.Errorf("todos-api request failed: %w", err)
}
defer response.Body.Close()
return nil
}</code></pre>
</div>
<h3>4. Run the profiler</h3>
<p class="short">These commands use the <code>rc</code> CLI. The <a href="cli.html">rc CLI</a> chapter shows how to install it and lists every command.</p>
<div class="example">
<div class="example-title"><span>Run</span></div>
<pre><code>rc profile generate \
--dir . \
--name request-logger-http \
--workload-uri github.com/runtimeconditions/rc-demos/apps/request-logger-http \
--workload-version v0.1.0 \
--out profile.yaml</code></pre>
</div>
<p class="short">The profiler parses and type-checks your module, so it needs a Go toolchain and your dependencies downloaded. It reads literals, named constants, and typed composite literals. A value it cannot determine fails with the file and line, never with part of a Condition.</p>
</div>
<div class="tab-panel" id="tab-java" role="tabpanel" aria-labelledby="tab-button-java">
<h3>1. Add the packages</h3>
<p class="short">Add the binding packages from Maven Central, and install the profiler. It needs a <strong>JDK 17 or newer</strong>, not a JRE.</p>
<p class="short">These two are the packages for Common Integrations and Env Configuration. Every extension has packages in all four languages: see the <a href="extensions.html#binding-packages">Binding packages</a> table.</p>
<div class="example">
<div class="example-title"><span>Install</span></div>
<pre><code># pom.xml
<dependency>
<groupId>io.runtimeconditions.bindings</groupId>
<artifactId>runtimeconditions-common-integrations</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>io.runtimeconditions.bindings</groupId>
<artifactId>runtimeconditions-env-configuration</artifactId>
<version>0.1.0</version>
</dependency>
# the profiler
brew install runtimeconditions/tools/rc-profiler-java</code></pre>
</div>
<h3>2. Declare what the app needs</h3>
<p class="short">Each declaration is a call built from generated types, so the compiler checks every field. The calls do nothing when the app runs. The app below needs an HTTP API, with the environment variable that holds its URL, and a Redis cache, with two ways to find it.</p>
<div class="example">
<div class="example-title"><span>Conditions.java</span></div>
<pre><code>package demo;
import io.runtimeconditions.bindings.commonintegrations.Bindings;
import io.runtimeconditions.bindings.commonintegrations.Format;
import io.runtimeconditions.bindings.commonintegrations.Http;
import io.runtimeconditions.bindings.commonintegrations.HttpOperations;
import io.runtimeconditions.bindings.commonintegrations.HttpOperationsItem;
import io.runtimeconditions.bindings.commonintegrations.KeyValue;
import io.runtimeconditions.bindings.commonintegrations.KeyValueEngine;
import io.runtimeconditions.bindings.commonintegrations.Method;
import io.runtimeconditions.bindings.commonintegrations.Spec;
import io.runtimeconditions.bindings.envconfiguration.HttpConfiguration;
import io.runtimeconditions.bindings.envconfiguration.HttpConfigurationEnv;
import io.runtimeconditions.bindings.envconfiguration.HttpConfigurationEnvItem;
import io.runtimeconditions.bindings.envconfiguration.HttpConfigurationEnvItemProperty;
import io.runtimeconditions.bindings.envconfiguration.KeyValueConfiguration;
import io.runtimeconditions.bindings.envconfiguration.KeyValueConfigurationAlternatives;
import io.runtimeconditions.bindings.envconfiguration.KeyValueConfigurationAlternativesItem;
import io.runtimeconditions.bindings.envconfiguration.KeyValueConfigurationAlternativesItemEnv;
import io.runtimeconditions.bindings.envconfiguration.KeyValueConfigurationAlternativesItemEnvItem;
import io.runtimeconditions.bindings.envconfiguration.KeyValueConfigurationAlternativesItemEnvItemProperty;
import java.util.List;
final class Conditions {
static final Object TODOS_API = Bindings.api(
new Http(
new HttpOperations(List.of(new HttpOperationsItem(Method.GET, "/todos/{id}", null, null))),
new Spec(Format.OPENAPI, "catalog://api/default/todos-api", null)),
new HttpConfiguration(
null,
new HttpConfigurationEnv(List.of(
new HttpConfigurationEnvItem(
"TODOS_API_URL", HttpConfigurationEnvItemProperty.BASE_URL, null, null)))));
static final Object REQUEST_CACHE = Bindings.cache(
new KeyValue(KeyValueEngine.REDIS),
new KeyValueConfiguration(
new KeyValueConfigurationAlternatives(List.of(
new KeyValueConfigurationAlternativesItem(new KeyValueConfigurationAlternativesItemEnv(List.of(
new KeyValueConfigurationAlternativesItemEnvItem(
"REDIS_URL", KeyValueConfigurationAlternativesItemEnvItemProperty.URL, null, null)))),
new KeyValueConfigurationAlternativesItem(new KeyValueConfigurationAlternativesItemEnv(List.of(
new KeyValueConfigurationAlternativesItemEnvItem(
"REDIS_HOST", KeyValueConfigurationAlternativesItemEnvItemProperty.HOSTNAME, null, null),
new KeyValueConfigurationAlternativesItemEnvItem(
"REDIS_PORT", KeyValueConfigurationAlternativesItemEnvItemProperty.PORT, null, null)))))),
null));
}</code></pre>
</div>
<h3>3. Use the variables in normal code</h3>
<p class="short">The profile records the names <code>TODOS_API_URL</code> and <code>REDIS_URL</code>, not their values. The app reads them as it always did, and the platform supplies them later.</p>
<div class="example">
<div class="example-title"><span>TodosClient.java</span></div>
<pre><code>String baseUrl = System.getenv("TODOS_API_URL");
if (baseUrl == null || baseUrl.isBlank()) {
throw new IllegalStateException("TODOS_API_URL is not set");
}
HttpRequest request = HttpRequest.newBuilder(URI.create(baseUrl + "/todos/1")).build();</code></pre>
</div>
<h3>4. Run the profiler</h3>
<p class="short">These commands use the <code>rc</code> CLI. The <a href="cli.html">rc CLI</a> chapter shows how to install it and lists every command.</p>
<div class="example">
<div class="example-title"><span>Run</span></div>
<pre><code>rc profile java generate \
--project . \
--resolve-build-classpath \
--name request-logger-http \
--workload-uri github.com/runtimeconditions/rc-demos/apps/request-logger-http \
--workload-version v0.1.0 \
--out profile.yaml</code></pre>
</div>
<p class="short">The profiler needs to know where the binding jars are. <code>--resolve-build-classpath</code> asks your Maven or Gradle build, which <strong>runs your build</strong>, so it only happens when you ask. Without it, pass the jars with <code>--classpath a.jar:b.jar</code>. The profiler reads your source with the JDK's parser and never compiles or runs it.</p>
</div>
<div class="tab-panel" id="tab-python" role="tabpanel" aria-labelledby="tab-button-python">
<h3>1. Add the packages</h3>
<p class="short">Install the profiler and the bindings <strong>into the same virtual environment</strong>, because the profiler finds the bindings through that environment. Do not use <code>pipx</code>, which would give it an environment of its own.</p>
<p class="short">These two are the packages for Common Integrations and Env Configuration. Every extension has packages in all four languages: see the <a href="extensions.html#binding-packages">Binding packages</a> table.</p>
<div class="example">
<div class="example-title"><span>Install</span></div>
<pre><code>python3 -m venv .venv
.venv/bin/pip install runtimeconditions-profiler \
runtimeconditions-common-integrations \
runtimeconditions-env-configuration</code></pre>
</div>
<h3>2. Declare what the app needs</h3>
<p class="short">Each declaration is a call built from generated types, so the compiler checks every field. The calls do nothing when the app runs. The app below needs an HTTP API, with the environment variable that holds its URL, and a Redis cache, with two ways to find it.</p>
<div class="example">
<div class="example-title"><span>conditions.py</span></div>
<pre><code>from runtimeconditions_common_integrations import (
Format,
Http,
HttpOperationsItem,
KeyValue,
KeyValueEngine,
Method,
Spec,
api,
cache,
)
from runtimeconditions_env_configuration import (
HttpConfiguration,
HttpConfigurationEnvItem,
HttpConfigurationEnvItemProperty,
KeyValueConfiguration,
KeyValueConfigurationAlternativesItem,
KeyValueConfigurationAlternativesItemEnvItem,
KeyValueConfigurationAlternativesItemEnvItemProperty,
)
api(
Http(
spec=Spec(format=Format.OPENAPI, uri="catalog://api/default/todos-api"),
operations=[HttpOperationsItem(method=Method.GET, path="/todos/{id}")],
),
HttpConfiguration(
env=[
HttpConfigurationEnvItem(
name="TODOS_API_URL",
property=HttpConfigurationEnvItemProperty.BASE_URL,
)
]
),
)
cache(
KeyValue(engine=KeyValueEngine.REDIS),
KeyValueConfiguration(
alternatives=[
KeyValueConfigurationAlternativesItem(
env=[
KeyValueConfigurationAlternativesItemEnvItem(
name="REDIS_URL",
property=KeyValueConfigurationAlternativesItemEnvItemProperty.URL,
)
]
),
KeyValueConfigurationAlternativesItem(
env=[
KeyValueConfigurationAlternativesItemEnvItem(
name="REDIS_HOST",
property=KeyValueConfigurationAlternativesItemEnvItemProperty.HOSTNAME,
),
KeyValueConfigurationAlternativesItemEnvItem(
name="REDIS_PORT",
property=KeyValueConfigurationAlternativesItemEnvItemProperty.PORT,
),
]
),
]
),
)</code></pre>
</div>
<h3>3. Use the variables in normal code</h3>
<p class="short">The profile records the names <code>TODOS_API_URL</code> and <code>REDIS_URL</code>, not their values. The app reads them as it always did, and the platform supplies them later.</p>
<div class="example">
<div class="example-title"><span>todos_client.py</span></div>
<pre><code>import os
import urllib.request
base_url = os.environ["TODOS_API_URL"].rstrip("/")
urllib.request.urlopen(f"{base_url}/todos/1")</code></pre>
</div>
<h3>4. Run the profiler</h3>
<p class="short">These commands use the <code>rc</code> CLI. The <a href="cli.html">rc CLI</a> chapter shows how to install it and lists every command.</p>
<div class="example">
<div class="example-title"><span>Run</span></div>
<pre><code>export PATH="$PWD/.venv/bin:$PATH"
rc profile python generate \
--project . \
--name request-logger-http \
--workload-uri github.com/runtimeconditions/rc-demos/apps/request-logger-http \
--workload-version v0.1.0 \
--out profile.yaml</code></pre>
</div>
<p class="short">Python 3.11 or newer. The profiler reads your source and never imports the bindings or runs the app.</p>
</div>
<div class="tab-panel" id="tab-typescript" role="tabpanel" aria-labelledby="tab-button-typescript">
<h3>1. Add the packages</h3>
<p class="short">Add the binding packages to your project, and install the profiler. It needs Node.js.</p>
<p class="short">These two are the packages for Common Integrations and Env Configuration. Every extension has packages in all four languages: see the <a href="extensions.html#binding-packages">Binding packages</a> table.</p>
<div class="example">
<div class="example-title"><span>Install</span></div>
<pre><code>npm install @runtimeconditions/common-integrations @runtimeconditions/env-configuration
npm install --global @runtimeconditions/typescript-profiler</code></pre>
</div>
<h3>2. Declare what the app needs</h3>
<p class="short">Each declaration is a call built from generated types, so the compiler checks every field. The calls do nothing when the app runs. The app below needs an HTTP API, with the environment variable that holds its URL, and a Redis cache, with two ways to find it.</p>
<div class="example">
<div class="example-title"><span>src/conditions.ts</span></div>
<pre><code>import {
api,
cache,
Format,
Http,
HttpOperationsItem,
KeyValue,
KeyValueEngine,
Method,
Spec,
} from "@runtimeconditions/common-integrations";
import {
HttpConfiguration,
HttpConfigurationEnvItem,
HttpConfigurationEnvItemProperty,
KeyValueConfiguration,
KeyValueConfigurationAlternativesItem,
KeyValueConfigurationAlternativesItemEnvItem,
KeyValueConfigurationAlternativesItemEnvItemProperty,
} from "@runtimeconditions/env-configuration";
api(
new Http({
spec: new Spec({ format: Format.Openapi, uri: "catalog://api/default/todos-api" }),
operations: [new HttpOperationsItem({ method: Method.Get, path: "/todos/{id}" })],
}),
new HttpConfiguration({
env: [
new HttpConfigurationEnvItem({
name: "TODOS_API_URL",
property: HttpConfigurationEnvItemProperty.BaseUrl,
}),
],
}),
);
cache(
new KeyValue({ engine: KeyValueEngine.Redis }),
new KeyValueConfiguration({
alternatives: [
new KeyValueConfigurationAlternativesItem({
env: [
new KeyValueConfigurationAlternativesItemEnvItem({
name: "REDIS_URL",
property: KeyValueConfigurationAlternativesItemEnvItemProperty.Url,
}),
],
}),
new KeyValueConfigurationAlternativesItem({
env: [
new KeyValueConfigurationAlternativesItemEnvItem({
name: "REDIS_HOST",
property: KeyValueConfigurationAlternativesItemEnvItemProperty.Hostname,
}),
new KeyValueConfigurationAlternativesItemEnvItem({
name: "REDIS_PORT",
property: KeyValueConfigurationAlternativesItemEnvItemProperty.Port,
}),
],
}),
],
}),
);</code></pre>
</div>
<h3>3. Use the variables in normal code</h3>
<p class="short">The profile records the names <code>TODOS_API_URL</code> and <code>REDIS_URL</code>, not their values. The app reads them as it always did, and the platform supplies them later.</p>
<div class="example">
<div class="example-title"><span>src/todosClient.ts</span></div>
<pre><code>const baseUrl = (process.env.TODOS_API_URL ?? "").replace(/\/$/, "");
if (!baseUrl) {
throw new Error("TODOS_API_URL is not set");
}
await fetch(`${baseUrl}/todos/1`);</code></pre>
</div>
<h3>4. Run the profiler</h3>
<p class="short">These commands use the <code>rc</code> CLI. The <a href="cli.html">rc CLI</a> chapter shows how to install it and lists every command.</p>
<div class="example">
<div class="example-title"><span>Run</span></div>
<pre><code>rc profile typescript generate \
--project . \
--name request-logger-http \
--workload-uri github.com/runtimeconditions/rc-demos/apps/request-logger-http \
--workload-version v0.1.0 \
--out profile.yaml</code></pre>
</div>
<p class="short">The profiler reads your TypeScript source and never runs it.</p>
</div>
</div>
</section>
<section class="section">
<h2>The profile every language writes</h2>
<p class="short">
The four <a href="cli.html#profilers">profilers</a> write the same profile for these declarations. A profiler writes the extensions in the short form, the extension id with its version, and it does not name the Conditions: <code>name</code> is optional, and a hand-written profile can add one. Without <code>--out</code> the profile is printed, and a failed run leaves an existing output file alone.
</p>
<div class="example">
<div class="example-title">profile.yaml</div>
<pre><code>apiVersion: runtimeconditions.io/v1alpha1
kind: RuntimeConditionsProfile
metadata:
name: request-logger-http
workload:
uri: github.com/runtimeconditions/rc-demos/apps/request-logger-http
version: v0.1.0
extensions:
- https://runtimeconditions.io/extensions/rc/common-integrations:v1alpha2
- https://runtimeconditions.io/extensions/rc/env-configuration:v1alpha2
conditions:
- kind: api
interface:
type: http
operations:
- method: GET
path: /todos/{id}
spec:
format: openapi
uri: catalog://api/default/todos-api
configuration:
env:
- name: TODOS_API_URL
property: baseUrl
- kind: cache
interface:
type: key_value
engine: redis
configuration:
alternatives:
- env:
- name: REDIS_URL
property: url
- env:
- name: REDIS_HOST
property: hostname
- name: REDIS_PORT
property: port</code></pre>
</div>
</section>
<nav class="page-nav" aria-label="Page navigation">
<a class="page-nav-prev" href="spec.html"><small>Previous</small><span>Profile shape</span></a>
<a class="page-nav-next" href="extensions.html"><small>Next</small><span>Extensions</span></a>
</nav>
</main>
</div>
<footer class="footer">
<div class="footer-inner">
<div class="footer-brand">
<a class="footer-logo" href="index.html"><img src="assets/runtime-conditions-logo.svg" width="141" height="48" alt="Runtime Conditions"></a>
<p>A machine-readable way for developers to declare what an app needs to run, so the platform can provide it.</p>
<div class="footer-social">
<a class="social-link social-github" href="https://github.com/runtimeconditions" aria-label="Runtime Conditions on GitHub" target="_blank" rel="noopener noreferrer"><svg class="nav-icon" viewBox="0 0 24 24" width="20" height="20" fill="currentColor" aria-hidden="true" focusable="false"><path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"/></svg></a>
<a class="social-link social-slack" href="https://cloud-native.slack.com/archives/C0C0R4M65FZ" aria-label="Runtime Conditions on the CNCF Slack" target="_blank" rel="noopener noreferrer"><svg class="nav-icon" viewBox="0 0 24 24" width="20" height="20" fill="currentColor" aria-hidden="true" focusable="false"><path class="slack-red" d="M5.042 15.165a2.528 2.528 0 0 1-2.52 2.523A2.528 2.528 0 0 1 0 15.165a2.527 2.527 0 0 1 2.522-2.52h2.52v2.52zM6.313 15.165a2.527 2.527 0 0 1 2.521-2.52 2.527 2.527 0 0 1 2.521 2.52v6.313A2.528 2.528 0 0 1 8.834 24a2.528 2.528 0 0 1-2.521-2.522v-6.313z"/><path class="slack-blue" d="M8.834 5.042a2.528 2.528 0 0 1-2.521-2.52A2.528 2.528 0 0 1 8.834 0a2.528 2.528 0 0 1 2.521 2.522v2.52H8.834zM8.834 6.313a2.528 2.528 0 0 1 2.521 2.521 2.528 2.528 0 0 1-2.521 2.521H2.522A2.528 2.528 0 0 1 0 8.834a2.528 2.528 0 0 1 2.522-2.521h6.312z"/><path class="slack-green" d="M18.956 8.834a2.528 2.528 0 0 1 2.522-2.521A2.528 2.528 0 0 1 24 8.834a2.528 2.528 0 0 1-2.522 2.521h-2.522V8.834zM17.688 8.834a2.528 2.528 0 0 1-2.523 2.521 2.527 2.527 0 0 1-2.52-2.521V2.522A2.527 2.527 0 0 1 15.165 0a2.528 2.528 0 0 1 2.523 2.522v6.312z"/><path class="slack-yellow" d="M15.165 18.956a2.528 2.528 0 0 1 2.523 2.522A2.528 2.528 0 0 1 15.165 24a2.527 2.527 0 0 1-2.52-2.522v-2.522h2.52zM15.165 17.688a2.527 2.527 0 0 1-2.52-2.523 2.526 2.526 0 0 1 2.52-2.52h6.313A2.527 2.527 0 0 1 24 15.165a2.528 2.528 0 0 1-2.522 2.523h-6.313z"/></svg></a>
</div>
</div>
<nav class="footer-col" aria-label="Guide">
<h2>Guide</h2>
<ul>
<li><a href="index.html">Start here</a></li>
<li><a href="concepts.html">Core concepts</a></li>
<li><a href="spec.html">Profile shape</a></li>
<li><a href="developers.html">Code to profile</a></li>
<li><a href="cli.html">rc CLI</a></li>
<li><a href="faq.html">FAQ</a></li>
</ul>
</nav>
<nav class="footer-col" aria-label="Project">
<h2>Project</h2>
<ul>
<li><a href="https://github.com/runtimeconditions/spec/blob/main/docs/sixth-draft.md" target="_blank" rel="noopener noreferrer">Current draft</a></li>
<li><a href="https://extensions.runtimeconditions.io/" target="_blank" rel="noopener noreferrer">Extension registry</a></li>
<li><a href="https://github.com/runtimeconditions/rc-demos/blob/main/README.md" target="_blank" rel="noopener noreferrer">Run the demo</a></li>
<li><a href="reference.html">Source map</a></li>
</ul>
</nav>
<nav class="footer-col" aria-label="Community">
<h2>Community</h2>
<ul>
<li><a href="https://github.com/runtimeconditions" target="_blank" rel="noopener noreferrer">GitHub</a></li>
<li><a href="https://cloud-native.slack.com/archives/C0C0R4M65FZ" target="_blank" rel="noopener noreferrer">CNCF Slack</a></li>
<li><a href="https://github.com/runtimeconditions/runtimeconditions.github.io/issues" target="_blank" rel="noopener noreferrer">Improve this guide</a></li>
</ul>
</nav>
</div>
<div class="footer-bottom">
<span>© 2026 Runtime Conditions contributors.</span>
<span>Runtime Conditions is seeking adoption by an established parent project.</span>
</div>
</footer>
<script src="assets/tabs.js" defer></script>
<script src="assets/syntax.js" defer></script>
</body>
</html>