-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
215 additions
and
478 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 was deleted.
Oops, something went wrong.
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,59 @@ | ||
package slp | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
|
||
"github.com/kaz/pprotein/internal/collect" | ||
"github.com/kaz/pprotein/internal/extproc" | ||
"github.com/kaz/pprotein/internal/persistent" | ||
"github.com/kaz/pprotein/internal/storage" | ||
"github.com/labstack/echo/v4" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type ( | ||
handler struct { | ||
opts *collect.Options | ||
config *persistent.Handler | ||
} | ||
) | ||
|
||
//go:embed slp.yml | ||
var defaultConfig []byte | ||
|
||
func NewHandler(opts *collect.Options, store storage.Storage) (*handler, error) { | ||
h := &handler{ | ||
opts: opts, | ||
} | ||
|
||
config, err := persistent.New(store, "slp.yml", defaultConfig, h.sanitize) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create targets: %w", err) | ||
} | ||
h.config = config | ||
|
||
return h, nil | ||
} | ||
|
||
func (h *handler) Register(g *echo.Group) error { | ||
h.config.RegisterHandlers(g.Group("/config")) | ||
|
||
if err := extproc.NewHandler(&processor{confPath: h.config.GetPath()}, h.opts).Register(g); err != nil { | ||
return fmt.Errorf("failed to register extproc handlers: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func (h *handler) sanitize(raw []byte) ([]byte, error) { | ||
var config interface{} | ||
if err := yaml.Unmarshal(raw, &config); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal: %w", err) | ||
} | ||
|
||
res, err := yaml.Marshal(config) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal: %w", err) | ||
} | ||
return res, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bundle_values: true | ||
bundle_where_in: true | ||
filters: Query matches "^(SELECT|INSERT|UPDATE|REPLACE) " | ||
limit: 65536 |
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 |
---|---|---|
@@ -1,142 +1,23 @@ | ||
<template> | ||
<section> | ||
<pre v-if="!logData">Loading ...</pre> | ||
<div v-else class="container"> | ||
<table border="1"> | ||
<thead> | ||
<tr> | ||
<th v-for="h in header" :key="h" @click="sortBy(h)"> | ||
<span> | ||
{{ h }} | ||
<span v-if="sort == h" class="sortOrder"> | ||
{{ order == "asc" ? "▲" : "▼" }} | ||
</span> | ||
</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr v-for="d in sortedLogData" :key="d.toString()"> | ||
<td v-for="(v, idx) in d" :key="header[idx]">{{ v }}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<div class="tips">Click header to sort</div> | ||
</div> | ||
</section> | ||
<TsvTable :tsv="tsv" /> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from "vue"; | ||
import Pase, { ParseResult } from "papaparse"; | ||
const isNumeric = (v: string) => { | ||
return !isNaN(+v); | ||
}; | ||
import TsvTable from "./TsvTable.vue"; | ||
export default defineComponent({ | ||
components: { | ||
TsvTable, | ||
}, | ||
data() { | ||
return { | ||
logData: {} as ParseResult<string[]>, | ||
sort: "count", | ||
order: "desc", | ||
tsv: "", | ||
}; | ||
}, | ||
computed: { | ||
header: function () { | ||
if (!this.logData.data) { | ||
return []; | ||
} | ||
let data: string[][]; | ||
data = this.logData.data; | ||
return data[0]; | ||
}, | ||
sortedLogData: function () { | ||
if (!this.logData.data) { | ||
return []; | ||
} | ||
let data: string[][]; | ||
data = this.logData.data.slice(1); | ||
let index = this.header.findIndex((h: string) => h === this.sort); | ||
if (index == -1) { | ||
index = 0; | ||
} | ||
data.sort((a: string[], b: string[]): number => { | ||
if (isNumeric(a[index])) { | ||
return +a[index] - +b[index]; | ||
} else { | ||
if (a[index] < b[index]) { | ||
return -1; | ||
} else if (a[index] > b[index]) { | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
} | ||
}); | ||
if (this.order == "desc") { | ||
return data.reverse(); | ||
} else { | ||
return data; | ||
} | ||
}, | ||
}, | ||
async beforeCreate() { | ||
const resp = await fetch(`/api/httplog/${this.$route.params.id}`); | ||
const text = await resp.text(); | ||
const logData = Pase.parse<string[]>(text, { skipEmptyLines: true }); | ||
this.logData = logData; | ||
}, | ||
methods: { | ||
sortBy(key: string) { | ||
if (this.sort === key) { | ||
this.order = this.order == "desc" ? "asc" : "desc"; | ||
} else { | ||
this.sort = key; | ||
this.order = "desc"; | ||
} | ||
}, | ||
this.tsv = await resp.text(); | ||
}, | ||
}); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
section { | ||
margin: 2em; | ||
} | ||
pre { | ||
overflow: auto; | ||
flex: 1 0 auto; | ||
} | ||
.container { | ||
overflow: scroll; | ||
} | ||
table { | ||
border-collapse: collapse; | ||
} | ||
td, | ||
th { | ||
padding: 0.5em 1em; | ||
border: 1px solid #999; | ||
} | ||
th > span { | ||
cursor: pointer; | ||
.sortOrder { | ||
font-size: 0.4em; | ||
color: blue; | ||
} | ||
} | ||
.tips { | ||
margin-top: 3em; | ||
text-align: right; | ||
} | ||
</style> |
Oops, something went wrong.