Skip to content

Commit

Permalink
Merge branch 'main' into chore/mixin-namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Syndlex authored Mar 10, 2025
2 parents 555f830 + e3881e8 commit c41bc80
Show file tree
Hide file tree
Showing 4,807 changed files with 5,749,770 additions and 135,027 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
104 changes: 104 additions & 0 deletions .cursor/rules/frontend.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
description: building frontend code in react and typescript
globs: *.tsx,*.ts,*.css
---
You are an expert in TypeScript, Node.js, react-dom router, React, Shadcn UI, Radix UI and Tailwind.

# Key Principles

- Write concise, technical TypeScript code with accurate examples.
- Use functional and declarative programming patterns; avoid classes.
- Prefer iteration and modularization over code duplication.
- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).
- Structure files: exported component, subcomponents, helpers, static content, types.

# Component Composition

Break down complex UIs into smaller, more manageable parts, which can be easily reused across different parts of the application.

- Reusability: Components can be easily reused across different parts of the application, making it easier to maintain and update the UI.
- Modularity: Breaking the UI down into smaller, more manageable components makes it easier to understand and work with, particularly for larger and more complex applications.
- Separation of Concerns: By separating the UI into smaller components, each component can focus on its own specific functionality, making it easier to test and debug.
- Code Maintainability: Using smaller components that are easy to understand and maintain makes it easier to make changes and update the application over time.

Avoid large components with nested rendering functions


# State

- useState - for simpler states that are independent
- useReducer - for more complex states where on a single action you want to update several pieces of state
- context + hooks = good state management don't use other library
- prefix -context and -provider for context and respective provider.

# Naming Conventions

- Use lowercase with dashes for directories (e.g., components/auth-wizard).
- Favor named exports for components.

# TypeScript Usage

- Use TypeScript for all code; prefer interfaces over types.
- Avoid enums; use maps instead.
- Use functional components with TypeScript interfaces.

# Syntax and Formatting

- Use the "function" keyword for pure functions.
- Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.
- Use declarative JSX.
- Use arrow functions for improving code readability and reducing verbosity, especially for smaller functions like event handlers or callback functions.
- Avoid using inline styles

## Project Structure

Colocate things as close as possible to where it's being used

```
src/
├── components/ # React components
│ ├── ui/ # Shadcn UI components
│ │ ├── errors/ # Error handling components
│ │ └── breadcrumbs/ # Navigation breadcrumbs
│ ├── shared/ # Shared components used across pages
│ │ └── {pagename}/ # Page-specific components
│ ├── common/ # Truly reusable components
│ └── features/ # Complex feature modules
│ └── theme/ # Theme-related components and logic
├── pages/ # Page components and routes
├── layout/ # Layout components
├── hooks/ # Custom React hooks
├── contexts/ # React context providers
├── lib/ # Utility functions and constants
└── types/ # TypeScript type definitions
```

DON'T modify shadcn component directly they are stored in src/components/ui/*


# UI and Styling

- Use Shadcn UI, Radix, and Tailwind for components and styling.
- Implement responsive design with Tailwind CSS.

# Performance Optimization

- Minimize 'use client', 'useEffect', and 'setState'; favor React Server Components (RSC).
- Wrap client components in Suspense with fallback.
- Use dynamic loading for non-critical components.
- Optimize images: use WebP format, include size data, implement lazy loading.

# Key Conventions

- Use 'nuqs' for URL search parameter state management.
- Optimize Web Vitals (LCP, CLS, FID).
- Limit 'use client':

# Unit Tests

Unit testing is done to test individual components of the React application involving testing the functionality of each component in isolation to ensure that it works as intended.

- Use Jest for unit testing.
- Write unit tests for each component.
- Use React Testing Library for testing components.
- Use React Testing Library for testing components.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"image": "grafana/loki-build-image:0.34.1",
"image": "grafana/loki-build-image:0.34.6",
"containerEnv": {
"BUILD_IN_CONTAINER": "false"
},
Expand Down
22 changes: 22 additions & 0 deletions .github/actions/setup-k3d/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Setup K3D Cluster
description: Setup a K3D cluster

runs:
using: "composite"
steps:

- name: Install k3d
shell: bash
run: |
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
- name: Create k3d cluster with local registry
shell: bash
run: |
k3d registry create registry.local --port 5000
k3d cluster create k3d-cluster --registry-use k3d-registry.local:5000
- name: Set kubectl context to k3d cluster
shell: bash
run: |
k3d kubeconfig merge k3d-cluster --kubeconfig-switch-context
2 changes: 1 addition & 1 deletion .github/jsonnetfile.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"subdir": "workflows"
}
},
"version": "cfa24256090828f566f1ba59292ce65d8db4a4ae"
"version": "965213a0fe2632438ab0524d606cb71d414e2388"
}
],
"legacyImports": true
Expand Down
4 changes: 2 additions & 2 deletions .github/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"subdir": "workflows"
}
},
"version": "cfa24256090828f566f1ba59292ce65d8db4a4ae",
"sum": "tml1dcFlo15kEE6JvN/nPY2xkhfeF3ERZjAyFbnguHA="
"version": "965213a0fe2632438ab0524d606cb71d414e2388",
"sum": "DXmqwVyytIhA0tHlMQUCLD8buVjjCb04YcIxJ3BLFqM="
}
],
"legacyImports": false
Expand Down
187 changes: 161 additions & 26 deletions .github/release-workflows.jsonnet
Original file line number Diff line number Diff line change
@@ -1,35 +1,139 @@
local lokiRelease = import 'workflows/main.jsonnet';

local build = lokiRelease.build;
local lokiRelease = import 'workflows/main.jsonnet',
job = lokiRelease.job,
step = lokiRelease.step,
build = lokiRelease.build;
local releaseLibRef = 'main';
local checkTemplate = 'grafana/loki-release/.github/workflows/check.yml@%s' % releaseLibRef;
local buildImageVersion = std.extVar('BUILD_IMAGE_VERSION');
local goVersion = std.extVar('GO_VERSION');
local buildImage = 'grafana/loki-build-image:%s' % buildImageVersion;
local golangCiLintVersion = 'v1.60.3';
local golangCiLintVersion = 'v1.64.5';
local imageBuildTimeoutMin = 60;
local imagePrefix = 'grafana';
local dockerPluginDir = 'clients/cmd/docker-driver';
local runner = import 'workflows/runner.libsonnet',
r = runner.withDefaultMapping(); // Do we need a different mapping?

local platforms = {
amd: [r.forPlatform('linux/amd64')],
arm: [r.forPlatform('linux/arm64'), r.forPlatform('linux/arm')],
all: self.amd + self.arm,
};

local imageJobs = {
loki: build.image('loki', 'cmd/loki'),
fluentd: build.image('fluent-plugin-loki', 'clients/cmd/fluentd', platform=['linux/amd64']),
'fluent-bit': build.image('fluent-bit-plugin-loki', 'clients/cmd/fluent-bit', platform=['linux/amd64']),
logstash: build.image('logstash-output-loki', 'clients/cmd/logstash', platform=['linux/amd64']),
logcli: build.image('logcli', 'cmd/logcli'),
'loki-canary': build.image('loki-canary', 'cmd/loki-canary'),
'loki-canary-boringcrypto': build.image('loki-canary-boringcrypto', 'cmd/loki-canary-boringcrypto'),
promtail: build.image('promtail', 'clients/cmd/promtail'),
querytee: build.image('loki-query-tee', 'cmd/querytee', platform=['linux/amd64']),
'loki-docker-driver': build.dockerPlugin('loki-docker-driver', dockerPluginDir, buildImage=buildImage, platform=['linux/amd64', 'linux/arm64']),
loki: build.image('loki', 'cmd/loki', platform=platforms.all),
fluentd: build.image('fluent-plugin-loki', 'clients/cmd/fluentd', platform=platforms.amd),
'fluent-bit': build.image('fluent-bit-plugin-loki', 'clients/cmd/fluent-bit', platform=platforms.amd),
logstash: build.image('logstash-output-loki', 'clients/cmd/logstash', platform=platforms.amd),
logcli: build.image('logcli', 'cmd/logcli', platform=platforms.all),
'loki-canary': build.image('loki-canary', 'cmd/loki-canary', platform=platforms.all),
'loki-canary-boringcrypto': build.image('loki-canary-boringcrypto', 'cmd/loki-canary-boringcrypto', platform=platforms.all),
promtail: build.image('promtail', 'clients/cmd/promtail', platform=platforms.all),
querytee: build.image('loki-query-tee', 'cmd/querytee', platform=platforms.amd),
'loki-docker-driver': build.dockerPlugin('loki-docker-driver', dockerPluginDir, buildImage=buildImage, platform=[r.forPlatform('linux/amd64'), r.forPlatform('linux/arm64')]),
};

local weeklyImageJobs = {
loki: build.weeklyImage('loki', 'cmd/loki'),
'loki-canary': build.weeklyImage('loki-canary', 'cmd/loki-canary'),
'loki-canary-boringcrypto': build.weeklyImage('loki-canary-boringcrypto', 'cmd/loki-canary-boringcrypto'),
promtail: build.weeklyImage('promtail', 'clients/cmd/promtail'),
loki: build.weeklyImage('loki', 'cmd/loki', platform=platforms.all),
'loki-canary': build.weeklyImage('loki-canary', 'cmd/loki-canary', platform=platforms.all),
'loki-canary-boringcrypto': build.weeklyImage('loki-canary-boringcrypto', 'cmd/loki-canary-boringcrypto', platform=platforms.all),
promtail: build.weeklyImage('promtail', 'clients/cmd/promtail', platform=platforms.all),
};

local lambdaPromtailJob =
job.new()
+ job.withNeeds(['check'])
+ job.withEnv({
BUILD_TIMEOUT: imageBuildTimeoutMin,
GO_VERSION: goVersion,
IMAGE_PREFIX: 'public.ecr.aws/grafana',
RELEASE_LIB_REF: releaseLibRef,
RELEASE_REPO: 'grafana/loki',
REPO: 'loki',
})
+ job.withOutputs({
image_digest_linux_amd64: '${{ steps.digest.outputs.digest_linux_amd64 }}',
image_digest_linux_arm64: '${{ steps.digest.outputs.digest_linux_arm64 }}',
image_name: '${{ steps.weekly-version.outputs.image_name }}',
image_tag: '${{ steps.weekly-version.outputs.image_version }}',
})
+ job.withStrategy({
'fail-fast': true,
matrix: {
include: [
{ arch: 'linux/amd64', runs_on: ['github-hosted-ubuntu-x64-small'] },
{ arch: 'linux/arm64', runs_on: ['github-hosted-ubuntu-arm64-small'] },
],
},
})
+ { 'runs-on': '${{ matrix.runs_on }}' }
+ job.withSteps([
step.new('pull release library code', 'actions/checkout@v4')
+ step.with({
path: 'lib',
ref: '${{ env.RELEASE_LIB_REF }}',
repository: 'grafana/loki-release',
}),
step.new('pull code to release', 'actions/checkout@v4')
+ step.with({
path: 'release',
repository: '${{ env.RELEASE_REPO }}',
}),
step.new('setup node', 'actions/setup-node@v4')
+ step.with({
'node-version': '20',
}),
step.new('Set up Docker buildx', 'docker/setup-buildx-action@v3'),
step.new('get-secrets', 'grafana/shared-workflows/actions/[email protected]')
+ { id: 'get-secrets' }
+ step.with({
repo_secrets: |||
ECR_ACCESS_KEY=aws-credentials:access_key_id
ECR_SECRET_KEY=aws-credentials:secret_access_key
|||,
}),
step.new('Configure AWS credentials', 'aws-actions/configure-aws-credentials@v4')
+ step.with({
'aws-access-key-id': '${{ env.ECR_ACCESS_KEY }}',
'aws-secret-access-key': '${{ env.ECR_SECRET_KEY }}',
'aws-region': 'us-east-1',
}),
step.new('Login to Amazon ECR Public', 'aws-actions/amazon-ecr-login@v2')
+ step.with({
'registry-type': 'public',
}),
step.new('Get weekly version')
+ { id: 'weekly-version' }
+ { 'working-directory': 'release' }
+ step.withRun(|||
version=$(./tools/image-tag)
echo "image_version=$version" >> $GITHUB_OUTPUT
echo "image_name=${{ env.IMAGE_PREFIX }}/lambda-promtail" >> $GITHUB_OUTPUT
echo "image_full_name=${{ env.IMAGE_PREFIX }}/lambda-promtail:$version" >> $GITHUB_OUTPUT
|||),
step.new('Prepare tag name')
+ { id: 'prepare-tag' }
+ step.withRun(|||
arch=$(echo ${{ matrix.arch }} | cut -d'/' -f2)
echo "IMAGE_TAG=${{ steps.weekly-version.outputs.image_name }}:${{ steps.weekly-version.outputs.image_version }}-${arch}" >> $GITHUB_OUTPUT
|||),
step.new('Build and push', 'docker/build-push-action@v6')
+ { id: 'build-push' }
+ { 'timeout-minutes': '${{ fromJSON(env.BUILD_TIMEOUT) }}' }
+ step.with({
'build-args': |||
IMAGE_TAG=${{ steps.weekly-version.outputs.image_version }}
GO_VERSION=${{ env.GO_VERSION }}
|||,
context: 'release',
file: 'release/tools/lambda-promtail/Dockerfile',
outputs: 'type=image,push=true',
platform: '${{ matrix.arch }}',
provenance: false,
tags: '${{ steps.prepare-tag.outputs.IMAGE_TAG }}',
}),
]);

{
'patch-release-pr.yml': std.manifestYamlDoc(
lokiRelease.releasePRWorkflow(
Expand Down Expand Up @@ -102,14 +206,15 @@ local weeklyImageJobs = {
},
}),
'images.yml': std.manifestYamlDoc({
name: 'publish images',
name: 'Publish images',
on: {
push: {
branches: [
'k[0-9]+*', // This is a weird glob pattern, not a regexp, do not use ".*", see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
'main',
],
},
workflow_dispatch: {},
},
permissions: {
'id-token': 'write',
Expand All @@ -127,16 +232,46 @@ local weeklyImageJobs = {
use_github_app_token: true,
},
},
} + std.mapWithKey(function(name, job)
job
+ lokiRelease.job.withNeeds(['check'])
+ {
env: {
} + {
['%s-image' % name]:
weeklyImageJobs[name]
+ job.withNeeds(['check'])
+ job.withEnv({
BUILD_TIMEOUT: imageBuildTimeoutMin,
RELEASE_REPO: 'grafana/loki',
RELEASE_LIB_REF: releaseLibRef,
IMAGE_PREFIX: imagePrefix,
},
}, weeklyImageJobs),
GO_VERSION: goVersion,
})
for name in std.objectFields(weeklyImageJobs)
} + {
'lambda-promtail-image': lambdaPromtailJob,
} + {
['%s-manifest' % name]:
job.new()
+ job.withNeeds(['%s-image' % name])
+ job.withEnv({
BUILD_TIMEOUT: imageBuildTimeoutMin,
})
+ job.withSteps([
step.new('Set up Docker buildx', 'docker/setup-buildx-action@v3'),
step.new('Login to DockerHub (from Vault)', 'grafana/shared-workflows/actions/dockerhub-login@main'),
step.new('Publish multi-arch manifest')
+ step.withRun(|||
# Unfortunately there is no better way atm than having a separate named output for each digest
echo 'linux/arm64 ${{ needs.%(name)s.outputs.image_digest_linux_amd64 }}'
echo 'linux/amd64 ${{ needs.%(name)s.outputs.image_digest_linux_arm64 }}'
echo 'linux/arm ${{ needs.%(name)s.outputs.image_digest_linux_arm }}'
IMAGE=${{ needs.%(name)s.outputs.image_name }}:${{ needs.%(name)s.outputs.image_tag }}
echo "Create multi-arch manifest for $IMAGE"
docker buildx imagetools create -t $IMAGE \
${{ needs.%(name)s.outputs.image_name }}@${{ needs.%(name)s.outputs.image_digest_linux_amd64 }} \
${{ needs.%(name)s.outputs.image_name }}@${{ needs.%(name)s.outputs.image_digest_linux_arm64 }} \
${{ needs.%(name)s.outputs.image_name }}@${{ needs.%(name)s.outputs.image_digest_linux_arm }}
docker buildx imagetools inspect $IMAGE
||| % { name: '%s-image' % name }),
])
for name in std.objectFields(weeklyImageJobs)
},
}),
}
Loading

0 comments on commit c41bc80

Please sign in to comment.