Skip to content

Commit

Permalink
various things
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhaynes committed May 3, 2024
1 parent 67e578a commit 4a7d3f0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
18 changes: 9 additions & 9 deletions lambda_telementry_api/lib/lambda_telementry_api-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import { join } from 'path';
export class LambdaTelementryApiStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const account=this.account
const region=this.region
const account = this.account
const region = this.region

const extensionName = "grafana-loki-extension"
const layerVersion="1"
const loki_ip="3.67.195.192"
const layerVersion = "1"
const LOKI_URL = "3.67.195.192"
const distpatch_min_batch_size = "10"
const lambdatelematryApiLayerArn = "arn:aws:lambda:"+region+":"+account+":layer:"+extensionName+":"+layerVersion

const lambdatelematryApiLayerArn = "arn:aws:lambda:" + region + ":" + account + ":layer:" + extensionName + ":" + layerVersion
const ltaLayer = lambda.LayerVersion.fromLayerVersionArn(this, "ltalayer", lambdatelematryApiLayerArn)

let functions= [];
let functions = [];

// GO **********
const fnGO = new lambda.Function(this, 'telemetry-api-starter-go', {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class LambdaTelementryApiStack extends cdk.Stack {
functions[i].addEnvironment("Bucket", bucky.bucketName)
functions[i].addEnvironment("TableName", table.tableName)
functions[i].addEnvironment("DISPATCH_MIN_BATCH_SIZE", distpatch_min_batch_size)
functions[i].addEnvironment("LOKI_IP", loki_ip)
functions[i].addEnvironment("LOKI_URL", LOKI_URL)
bucky.grantRead(functions[i])
table.grantReadWriteData(functions[i]);
topic.addSubscription(new subscriptions.LambdaSubscription(functions[i]));
Expand Down
6 changes: 3 additions & 3 deletions loki_extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Based on the example in https://github.com/aws-samples/aws-lambda-extensions/tre
This proof-of-concept code is not production ready. Use it with your own discretion after testing thoroughly.


This sample extension:
This sample extension:
1. Registers the extension with Lambda Extensions API (see `extensionApi/client.go`)
2. Starts a local HTTP server to receive incoming telemetry events from the Telemetry API (see `telemetryApi/listener.go`)
3. Subscribes to the Telemetry API to start receiving incoming telemetry events (see `telemetryApi/client.go`)
Expand All @@ -30,6 +30,6 @@ Note the ARN and use it as the Lambda Layer.

Configure the extension by setting below environment variables

* `LOKI_IP` - the IP of the loki server. This poc runs *without* authentocation.
* `DISPATCH_MIN_BATCH_SIZE` - optimize dispatching telemetry by telling the dispatcher how many log events you want it to batch. On function invoke the telemetry will be dispatched only if number of log events collected so far is greater than `DISPATCH_MIN_BATCH_SIZE`. On function shutdown the telemetry will be dispatched regardless of how many log events were collected so far.
* `LOKI_URL` - the URL of the loki server. This poc runs *without* authentocation.
* `DISPATCH_MIN_BATCH_SIZE` - optimize dispatching telemetry by telling the dispatcher how many log events you want it to batch. On function invoke the telemetry will be dispatched only if number of log events collected so far is greater than `DISPATCH_MIN_BATCH_SIZE`. On function shutdown the telemetry will be dispatched regardless of how many log events were collected so far.

4 changes: 2 additions & 2 deletions loki_extension/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ tasks:
deps: [build]
cmds:
- chmod +x extensions/{{.EXTENSION}}
- rm -f extension.zip
- rm -f extension.zip
- zip -r extension.zip extensions/
- ARN=`aws lambda publish-layer-version --layer-name "grafana-loki-extension" --region eu-central-1 --compatible-runtimes nodejs16.x go1.x python3.9 --zip-file "fileb://extension.zip" --query "LayerVersionArn" --output text` && echo $ARN
- ARN=`aws lambda publish-layer-version --layer-name "grafana-loki-extension" --compatible-runtimes nodejs16.x go1.x python3.9 --zip-file "fileb://extension.zip" --query "LayerVersionArn" --output text` && echo $ARN
silent: false

build:
Expand Down
9 changes: 6 additions & 3 deletions loki_extension/loki/promtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ func init() {
sendLabels = append(labels, fmt.Sprintf("%s = %s", key, val))
}

lokiIp := os.Getenv("LOKI_IP")
lokiIp := os.Getenv("LOKI_URL")
if len(lokiIp) == 0 {
panic("LOKI Ip undefined")
}

conf = promtail.ClientConfig{
PushURL: fmt.Sprintf("%s/api/v1/push", lokiIp),
Labels: fmt.Sprintf("{%s}", strings.Join(labels, ",")),
BatchWait: 5 * time.Second,
BatchEntriesNumber: 10000,
SendLevel: promtail.INFO,
PrintLevel: promtail.ERROR,
SendLevel: promtail.DEBUG,
PrintLevel: promtail.DEBUG,
}
loki, err = promtail.NewClientProto(conf)
if err != nil {
Expand All @@ -61,6 +62,8 @@ func init() {

func LokiSend(record *string) {
tstamp := time.Now().String()
loki.Infof("tomhayn hello")
loki.Infof("%s", conf.PushURL)
loki.Infof("%s, time = %s, record = %v\n", strings.Join(sendLabels, ", "), tstamp, *record)
}

Expand Down

0 comments on commit 4a7d3f0

Please sign in to comment.