-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
87 differentiate between false and true verifications (#260)
* fix(logging): use axiom again for logs * feat(ui): differentiate between success or denied verifications resolves #87
- Loading branch information
Showing
16 changed files
with
347 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package logging | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"log" | ||
"time" | ||
|
||
ax "github.com/axiomhq/axiom-go/axiom" | ||
) | ||
|
||
type AxiomWriter struct { | ||
eventsC chan ax.Event | ||
} | ||
|
||
type AxiomWriterConfig struct { | ||
AxiomToken string | ||
AxiomOrgId string | ||
} | ||
|
||
func NewAxiomWriter(config AxiomWriterConfig) (*AxiomWriter, error) { | ||
|
||
client, err := ax.NewClient( | ||
ax.SetPersonalTokenConfig(config.AxiomToken, config.AxiomOrgId), | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to create axiom client") | ||
} | ||
a := &AxiomWriter{ | ||
eventsC: make(chan ax.Event), | ||
} | ||
|
||
go func() { | ||
_, err := client.IngestChannel(context.Background(), "agent", a.eventsC) | ||
if err != nil { | ||
log.Print("unable to ingest to axiom") | ||
} | ||
}() | ||
|
||
return a, nil | ||
} | ||
|
||
func (aw *AxiomWriter) Close() { | ||
close(aw.eventsC) | ||
} | ||
|
||
func (aw *AxiomWriter) Write(p []byte) (int, error) { | ||
e := make(map[string]any) | ||
|
||
err := json.Unmarshal(p, &e) | ||
if err != nil { | ||
return 0, err | ||
} | ||
e["_time"] = time.Now().UnixMilli() | ||
|
||
aw.eventsC <- e | ||
return len(p), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package util_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/unkeyed/unkey/apps/agent/pkg/util" | ||
) | ||
|
||
type TestStruct1 struct { | ||
Field1 string `json:"field1"` | ||
Field2 int `json:"field2"` | ||
} | ||
|
||
type TestStruct2 struct { | ||
Field3 string `json:"field3"` | ||
Field4 int `json:"field4"` | ||
} | ||
|
||
type NestedStruct struct { | ||
Inner TestStruct2 `json:"inner"` | ||
} | ||
|
||
func TestStructToMap_NilInput(t *testing.T) { | ||
result := util.StructToMap(nil) | ||
require.Empty(t, result) | ||
} | ||
|
||
func TestStructToMap_SimpleStruct(t *testing.T) { | ||
input := TestStruct1{ | ||
Field1: "value1", | ||
Field2: 42, | ||
} | ||
expected := map[string]interface{}{ | ||
"field1": "value1", | ||
"field2": 42, | ||
} | ||
result := util.StructToMap(input) | ||
require.Equal(t, expected, result) | ||
} | ||
|
||
func TestStructToMap_NestedStruct(t *testing.T) { | ||
input := NestedStruct{ | ||
Inner: TestStruct2{ | ||
Field3: "value3", | ||
Field4: 99, | ||
}, | ||
} | ||
expected := map[string]interface{}{ | ||
"inner": map[string]interface{}{ | ||
"field3": "value3", | ||
"field4": 99, | ||
}, | ||
} | ||
result := util.StructToMap(input) | ||
require.Equal(t, expected, result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
1893a0a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
unkey – ./
unkey-unkey.vercel.app
unkey.vercel.app
www.unkey.dev
unkey.dev
unkey-git-main-unkey.vercel.app