Skip to content

Commit c65a847

Browse files
authored
Merge pull request #68 from grafana/new-api
Add new API models, andpoints and auth methods + update admin management
2 parents 5f985b3 + 5d5dd51 commit c65a847

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+861
-461
lines changed

Diff for: .dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
quickpizza.db
2+
Makefile

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ k6/k6
1818
k6/extensions/internal/k6
1919
k6/extensions/k6
2020

21-
.vscode
21+
.vscode
22+
quickpizza.db

Diff for: Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ ENV PUBLIC_BACKEND_WS_ENDPOINT=${PUBLIC_BACKEND_WS_ENDPOINT}
1212
RUN npm install && \
1313
npm run build
1414

15-
FROM golang:1.21-bullseye AS builder
15+
FROM golang:1.22-bullseye AS builder
1616

1717
WORKDIR /app
1818
COPY . ./

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Example of header usage:
274274
```
275275
curl -X POST http://localhost:3333/api/pizza \
276276
-H "Content-Type: application/json" \
277-
-H "X-User-ID: 23423" \
277+
-H "Authorization: abcdef0123456789" \
278278
-H "x-error-record-recommendation: internal-error" \
279279
-H "x-error-record-recommendation-percentage: 20" \
280280
-d '{}'

Diff for: cmd/main.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ func main() {
2929
// Create an HTTP client configured from env vars.
3030
// If no specific env vars are set, this will return a http client that does not perform any retries.
3131
httpCli := clientFromEnv()
32-
33-
server, err := qphttp.NewServer()
34-
if err != nil {
35-
slog.Error("Cannot create server", "err", err)
36-
os.Exit(1)
37-
}
32+
server := qphttp.NewServer()
3833

3934
if otlpEndpoint, tracingEnabled := os.LookupEnv("QUICKPIZZA_OTLP_ENDPOINT"); tracingEnabled {
4035
ctx, cancel := context.WithCancel(context.Background())
@@ -141,7 +136,7 @@ func main() {
141136

142137
listen := ":3333"
143138
slog.Info("Starting QuickPizza", "listenAddress", listen)
144-
err = http.ListenAndServe(listen, server)
139+
err := http.ListenAndServe(listen, server)
145140
if err != nil {
146141
slog.Error("Running HTTP server", "err", err)
147142
os.Exit(1)
@@ -157,7 +152,10 @@ func clientFromEnv() *http.Client {
157152
Transport: otelhttp.NewTransport(
158153
nil, // Default transport.
159154
// Propagator will retrieve the tracer used in the server from memory.
160-
otelhttp.WithPropagators(propagation.TraceContext{}),
155+
otelhttp.WithPropagators(propagation.NewCompositeTextMapPropagator(
156+
propagation.TraceContext{},
157+
propagation.Baggage{},
158+
)),
161159
),
162160
}
163161

@@ -325,7 +323,7 @@ func envConfig(prefix string) map[string]string {
325323
return config
326324
}
327325

328-
// envDBUrl returns the specified db connection string from QUICKPIZZA_DB. It defaults to an in-memory sqlite instance
326+
// envDBConnString returns the specified db connection string from QUICKPIZZA_DB. It defaults to an in-memory sqlite instance
329327
func envDBConnString() string {
330328
v, found := os.LookupEnv("QUICKPIZZA_DB")
331329
if !found {

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
toolchain go1.22.4
66

77
require (
8-
github.com/go-chi/chi v1.5.4
8+
github.com/go-chi/chi/v5 v5.1.0
99
github.com/go-chi/cors v1.2.1
1010
github.com/grafana/pyroscope-go v1.1.1
1111
github.com/grafana/pyroscope-go/x/k6 v0.0.0-20240618140011-f1a626fc4fe0

Diff for: go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
6565
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
6666
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
6767
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
68-
github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=
69-
github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg=
68+
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
69+
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
7070
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
7171
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
7272
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=

Diff for: k6/browser/02.cookies.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function () {
2020
const pizzaContext = await browser.newContext();
2121
await pizzaContext.addCookies([
2222
{
23-
name: "X-User-ID",
23+
name: "FooBar",
2424
value: 123456,
2525
domain: BASE_URL,
2626
path: '/',
@@ -33,7 +33,7 @@ export default async function () {
3333

3434
check(cookies, {
3535
"cookie length of QuickPizza page": cookies => cookies.length === 1,
36-
"cookie name": cookies => cookies[0].name === "X-User-ID",
36+
"cookie name": cookies => cookies[0].name === "FooBar",
3737
"cookie value": cookies => cookies[0].value === "123456"
3838
});
3939

@@ -44,10 +44,10 @@ export default async function () {
4444
const anotherPage = await anotherContext.newPage();
4545
const anotherCookies = await anotherContext.cookies();
4646

47-
await anotherPage.goto('https://test.k6.io/');
47+
await anotherPage.goto('https://example.org/');
4848

4949
check(anotherCookies, {
50-
"cookie length of k6 test page": anotherCookies => anotherCookies.length === 0,
50+
"cookie length of example test page": anotherCookies => anotherCookies.length === 0,
5151
});
5252

5353
await anotherPage.close();

Diff for: k6/browser/07.hybrid.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function getPizza() {
7272
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
7373
headers: {
7474
'Content-Type': 'application/json',
75-
'X-User-ID': 123456,
75+
'Authorization': 'token abcdef0123456789',
7676
},
7777
});
7878
check(res, { "status is 200": (res) => res.status === 200 });
@@ -123,4 +123,4 @@ export async function pizzaRecommendations() {
123123
} finally {
124124
page.close();
125125
}
126-
}
126+
}

Diff for: k6/disruptor/01.basic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function () {
4949
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
5050
headers: {
5151
"Content-Type": "application/json",
52-
"X-User-ID": 23423,
52+
"Authorization": "token abcdef0123456789",
5353
},
5454
});
5555
check(res, {"status is 200": (res) => res.status === 200});

Diff for: k6/disruptor/02.error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function () {
4949
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
5050
headers: {
5151
"Content-Type": "application/json",
52-
"X-User-ID": 23423,
52+
"Authorization": "token abcdef0123456789",
5353
},
5454
});
5555
check(res, {"status is 200": (res) => res.status === 200});

Diff for: k6/extensions/01.basic-internal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default function() {
2121
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
2222
headers: {
2323
'Content-Type': 'application/json',
24-
'X-User-ID': 23423,
24+
'Authorization': 'token abcdef0123456789',
2525
},
2626
});
2727
check(res, { "status is 200": (res) => res.status === 200 });
@@ -35,4 +35,4 @@ export default function() {
3535
return followRestrictions;
3636
}});
3737
sleep(1);
38-
}
38+
}

Diff for: k6/foundations/01.basic.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export default function () {
2020
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
2121
headers: {
2222
'Content-Type': 'application/json',
23-
'X-User-ID': 23423,
23+
'Authorization': 'token abcdef0123456789',
2424
},
2525
});
2626
check(res, { "status is 200": (res) => res.status === 200 });
2727
console.log(`${res.json().pizza.name} (${res.json().pizza.ingredients.length} ingredients)`);
2828
sleep(1);
29-
}
29+
}

Diff for: k6/foundations/02.stages.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export default function () {
2323
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
2424
headers: {
2525
'Content-Type': 'application/json',
26-
'X-User-ID': 23423,
26+
'Authorization': 'token abcdef0123456789',
2727
},
2828
});
2929
check(res, { "status is 200": (res) => res.status === 200 });
3030
console.log(`${res.json().pizza.name} (${res.json().pizza.ingredients.length} ingredients)`);
3131
sleep(1);
32-
}
32+
}

Diff for: k6/foundations/03.lifecycle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default function () {
3030
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
3131
headers: {
3232
'Content-Type': 'application/json',
33-
'X-User-ID': 23423,
33+
'Authorization': 'token abcdef0123456789',
3434
},
3535
});
3636
check(res, { "status is 200": (res) => res.status === 200 });
@@ -41,4 +41,4 @@ export default function () {
4141
export function teardown(){
4242
// TODO: Send notification to Slack
4343
console.log("That's all folks!")
44-
}
44+
}

Diff for: k6/foundations/04.metrics.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function () {
3434
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
3535
headers: {
3636
'Content-Type': 'application/json',
37-
'X-User-ID': 23423,
37+
'Authorization': 'token abcdef0123456789',
3838
},
3939
});
4040
check(res, { "status is 200": (res) => res.status === 200 });
@@ -47,4 +47,4 @@ export default function () {
4747
export function teardown(){
4848
// TODO: Send notification to Slack
4949
console.log("That's all folks!")
50-
}
50+
}

Diff for: k6/foundations/05.thresholds.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default function () {
3939
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
4040
headers: {
4141
'Content-Type': 'application/json',
42-
'X-User-ID': 23423,
42+
'Authorization': 'token abcdef0123456789',
4343
},
4444
});
4545
check(res, { "status is 200": (res) => res.status === 200 });
@@ -52,4 +52,4 @@ export default function () {
5252
export function teardown(){
5353
// TODO: Send notification to Slack
5454
console.log("That's all folks!")
55-
}
55+
}

Diff for: k6/foundations/06.checks-with-thresholds.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function () {
4040
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
4141
headers: {
4242
'Content-Type': 'application/json',
43-
'X-User-ID': 23423,
43+
'Authorization': 'token abcdef0123456789',
4444
},
4545
});
4646
check(res, { "status is 200": (res) => res.status === 200 });
@@ -53,4 +53,4 @@ export default function () {
5353
export function teardown() {
5454
// TODO: Send notification to Slack
5555
console.log("That's all folks!")
56-
}
56+
}

Diff for: k6/foundations/07.scenarios.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function getPizza() {
5454
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
5555
headers: {
5656
'Content-Type': 'application/json',
57-
'X-User-ID': 23423,
57+
'Authorization': 'token abcdef0123456789',
5858
},
5959
});
6060
check(res, { "status is 200": (res) => res.status === 200 });
@@ -74,4 +74,4 @@ export function handleSummary(data) {
7474
'summary.json': JSON.stringify(data, null, 2),
7575
stdout: textSummary(data, { indent: " ", enableColors: true }),
7676
}
77-
}
77+
}

Diff for: k6/foundations/08.arrival-rate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function getPizza() {
5151
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
5252
headers: {
5353
'Content-Type': 'application/json',
54-
'X-User-ID': 23423,
54+
'Authorization': 'token abcdef0123456789',
5555
},
5656
});
5757
check(res, { "status is 200": (res) => res.status === 200 });
@@ -84,4 +84,4 @@ export function handleSummary(data) {
8484
'summary.json': JSON.stringify(data, null, 2),
8585
stdout: textSummary(data, { indent: " ", enableColors: true }),
8686
}
87-
}
87+
}

Diff for: k6/foundations/09.data.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function getPizza() {
5959
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
6060
headers: {
6161
'Content-Type': 'application/json',
62-
'X-User-ID': customers[Math.floor(Math.random() * customers.length)],
62+
'Authorization': 'token abcdef0123456789',
6363
},
6464
});
6565
check(res, { "status is 200": (res) => res.status === 200 });
@@ -79,4 +79,4 @@ export function handleSummary(data) {
7979
'summary.json': JSON.stringify(data, null, 2),
8080
stdout: textSummary(data, { indent: " ", enableColors: true }),
8181
}
82-
}
82+
}

Diff for: k6/foundations/10.summary.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default function () {
4141
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
4242
headers: {
4343
'Content-Type': 'application/json',
44-
'X-User-ID': 23423,
44+
'Authorization': 'token abcdef0123456789',
4545
},
4646
});
4747
check(res, { "status is 200": (res) => res.status === 200 });
@@ -61,4 +61,4 @@ export function handleSummary(data) {
6161
'summary.json': JSON.stringify(data, null, 2),
6262
stdout: textSummary(data, { indent: " ", enableColors: true }),
6363
}
64-
}
64+
}

Diff for: k6/foundations/11.composability.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function getPizza() {
7373
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
7474
headers: {
7575
"Content-Type": "application/json",
76-
"X-User-ID": customers[Math.floor(Math.random() * customers.length)],
76+
'Authorization': 'token abcdef0123456789',
7777
},
7878
});
7979
check(res, { "status is 200": (res) => res.status === 200 });

Diff for: k6/foundations/12.modularization.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function getPizza() {
6868
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
6969
headers: {
7070
'Content-Type': 'application/json',
71-
'X-User-ID': customers[Math.floor(Math.random() * customers.length)],
71+
'Authorization': 'token abcdef0123456789',
7272
},
7373
});
7474
check(res, { "status is 200": (res) => res.status === 200 });
@@ -92,4 +92,4 @@ export function handleSummary(data) {
9292
'summary.json': JSON.stringify(data, null, 2),
9393
stdout: textSummary(data, { indent: " ", enableColors: true }),
9494
}
95-
}
95+
}

Diff for: k6/foundations/14.basic.tracing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function () {
2525
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
2626
headers: {
2727
'Content-Type': 'application/json',
28-
'X-User-ID': 23423,
28+
'Authorization': 'token abcdef0123456789',
2929
},
3030
});
3131
check(res, { "status is 200": (res) => res.status === 200 });

Diff for: k6/foundations/15.basic.profiling.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function () {
2323
let res = http.post(`${BASE_URL}/api/pizza`, JSON.stringify(restrictions), {
2424
headers: {
2525
"Content-Type": "application/json",
26-
"X-User-ID": 23423,
26+
'Authorization': 'token abcdef0123456789',
2727
},
2828
});
2929
check(res, { "status is 200": (res) => res.status === 200 });

Diff for: k6/foundations/16.grpc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default () => {
1212
});
1313

1414
const data = { ingredients: ["Pepperoni", "Mozzarella"], dough: "Stuffed" };
15-
const response = client.invoke('quickpizza.GRPC/EvaluatePizza', data);
15+
const response = client.invoke('quickpizza.GRPC/RatePizza', data);
1616

1717
check(response, {
1818
'status is OK': (r) => r && r.status === StatusOK,

Diff for: pkg/database/catalog.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (c *Catalog) RecordRecommendation(ctx context.Context, pizza model.Pizza) e
9090
}
9191
_, err = tx.NewDelete().
9292
Model((*model.Pizza)(nil)).
93-
Where("id NOT IN (?)", tx.NewSelect().
93+
Where("id NOT IN (?) AND id > 100", tx.NewSelect().
9494
Model((*model.Pizza)(nil)).
9595
Order("created_at DESC").
9696
Column("id").

0 commit comments

Comments
 (0)