Get logs from Pods using Kubernetes API for function log command (#2623)

* add controller enablement flag
* throw an error if service not found
* add logs from Kubernetes in function log command
* pass context in function param
* add pod-namespace in function log command
* pass context in function param
* search for the pod in fn ns in the test
This commit is contained in:
neha_gupta
2022-11-17 13:13:33 +05:30
committed by GitHub
parent 6d117ad43a
commit 4cbe6a7061
7 changed files with 218 additions and 37 deletions
+20 -10
View File
@@ -17,25 +17,33 @@ limitations under the License.
package logdb
import (
"bytes"
"context"
"fmt"
"time"
v1 "github.com/fission/fission/pkg/apis/core/v1"
)
const (
INFLUXDB = "influxdb"
INFLUXDB = "influxdb"
KUBERNETES = "kubernetes"
)
type LogDatabase interface {
GetLogs(LogFilter) ([]LogEntry, error)
GetLogs(context.Context, LogFilter) (*bytes.Buffer, error)
}
type LogFilter struct {
Pod string
Function string
FuncUid string
Since time.Time
Reverse bool
RecordLimit int
Pod string
PodNamespace string
Function string
FuncUid string
Since time.Time
Reverse bool
RecordLimit int
FunctionObject *v1.Function
Details bool
}
type LogEntry struct {
@@ -69,10 +77,12 @@ func ByTimestamp(entries []LogEntry, desc bool) ByTimestampSort {
return ByTimestampSort{entries, desc}
}
func GetLogDB(dbType string, serverURL string) (LogDatabase, error) {
func GetLogDB(dbType string, ctx context.Context, logDBOptions LogDBOptions) (LogDatabase, error) {
switch dbType {
case INFLUXDB:
return NewInfluxDB(serverURL)
return NewInfluxDB(ctx, logDBOptions)
case KUBERNETES:
return NewKubernetesEndpoint(logDBOptions)
}
return nil, fmt.Errorf("log database type is incorrect, now only support %s", INFLUXDB)
}